package com.sailfish.springbootdemo.service.db1;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sailfish.springbootdemo.common.DB1EmailTemplates;
import com.sailfish.springbootdemo.common.ProcessIdConfig;
import com.sailfish.springbootdemo.common.StrToCompanys;
import com.sailfish.springbootdemo.configs.UserHeaderHolder;
import com.sailfish.springbootdemo.dao.db1.*;
import com.sailfish.springbootdemo.dao.db4.UserDao;
import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.*;
import com.sailfish.springbootdemo.pojo.db1.Base64;
import com.sailfish.springbootdemo.pojo.db2.MailAddress;
import com.sailfish.springbootdemo.pojo.db4.Operate;
import com.sailfish.springbootdemo.pojo.db4.User;
import com.sailfish.springbootdemo.service.db2.ThirdApiService;
import com.sailfish.springbootdemo.service.db4.OperateService;
import com.sailfish.springbootdemo.utils.CommonUtils;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;

@Service
public class PcbaLineServiceImpl implements PcbaLineService {

    @Autowired
    private PcbaLineDao pcbaLineDao;

    @Autowired
    private PcbaDeviceResourceDao pcbaDeviceResourceDao;

    @Autowired
    private PcbaDeviceDao pcbaDeviceDao;

    @Autowired
    private PcbaDeviceAuditDao pcbaDeviceAuditDao;

    @Autowired
    private PcbaWorkshopDao pcbaWorkshopDao;

    @Autowired
    private PcbaCompanyDao pcbaCompanyDao;

    @Autowired
    private PcbaProcessDao pcbaProcessDao;

    @Autowired
    private PcbaDeviceTypeDao pcbaDeviceTypeDao;

    @Autowired
    private LineLevelDao lineLevelDao;

    @Autowired
    private PcbaDeviceParamDao pcbaDeviceParamDao;

    @Autowired
    private TechDeviceParamDao techDeviceParamDao;

    @Autowired
    private BrandDao brandDao;

    @Autowired
    private BrandTypeDao brandTypeDao;

    @Autowired
    private LineBaseBigTypeDao lineBaseBigTypeDao;

    @Autowired
    private LineBaseSmallTypeDao lineBaseSmallTypeDao;

    @Autowired
    private LineBaseParamDao lineBaseParamDao;

    @Autowired
    private AuditHistoryDao auditHistoryDao;

    @Autowired
    private PcbaDeviceRelatedDeviceParamDao pcbaDeviceRelatedDeviceParamDao;

    @Autowired
    private PcbaDeviceRelatedTechParamDao pcbaDeviceRelatedTechParamDao;

    @Autowired
    private PcbaDeviceRelatedTechParamActualDao pcbaDeviceRelatedTechParamActualDao;

    @Autowired
    private LineTechCapacityValueDao lineTechCapacityValueDao;

    @Autowired
    private LineBaseCapacityValueDao lineBaseCapacityValueDao;

    @Autowired
    private LineTechCapacityValueService lineTechCapacityValueService;

    @Autowired
    private BaseCapacityRuleDao baseCapacityRuleDao;

    @Autowired
    private CoreAlgorithmService coreAlgorithmService;

    @Autowired
    private MaintenanceConfigDao maintenanceConfigDao;

    @Autowired
    private LineTechBigTypeDao lineTechBigTypeDao;

    @Autowired
    private LineTechSmallTypeDao lineTechSmallTypeDao;

    @Autowired
    private TechCapacityRuleDao techCapacityRuleDao;

    @Autowired
    private TechDeviceParamTypeDao techDeviceParamTypeDao;

    @Autowired
    private UserDao userDao;

    @Value("${personal.config.amazon-s3.url}")
    private String url;
    @Value("${personal.config.amazon-s3.file-bucket}")
    private String fileBucket;
    @Value("${personal.config.env}")
    private String env;

    @Autowired
    private ThirdApiService thirdApiService;

    @Value("${personal.config.file.file-save-url}")
    private String fileSaveUrl;

    @Qualifier("MysqlTransactionManager1")
    @Autowired
    private DataSourceTransactionManager transactionManager1;

    @Autowired
    private OperateService operateService;

    @Autowired
    private Base64Dao base64Dao;

    private String operateSmallType = "线体管理";

    @Autowired
    private StrToCompanys strToCompanys;

    @Value("${personal.config.sso.trusted-redirect-uri}")
    private String trustedRedirectUri;

    @Override
    public Result getAllPcbaLine(String searchPcbaLineName, Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId, Integer status, Integer paramsStatusDeclare, Integer paramsStatusActual, Integer paramsStatusBase, Integer page, Integer pageSize) {
        try {
            if (page == null || !CommonUtils.isNumeric(page.toString())) {
                return ResultUtil.error(500, "错误参数page", "Error Param page", null);
            }
            if (pageSize == null || !CommonUtils.isNumeric(pageSize.toString())) {
                return ResultUtil.error(500, "错误参数pageSize", "Error Param pageSize", null);
            }
            //String isInner = UserHeaderHolder.getIsInner();
            //String belongPcba = UserHeaderHolder.getBelongPcba();
//            if("2".equals(isInner) && "".equals(belongPcba)) {
//                return ResultUtil.error(500, "未设置用户所属CM厂", "Error Set User", null);
//            }
            List<Integer> companyIdList = strToCompanys.getPcbaCompanyIdListFromStr();
            int begin = (page - 1) * pageSize;
            List<PcbaLine> list = pcbaLineDao.getAllPcbaLine(searchPcbaLineName, pcbaCompanyId, pcbaWorkshopId, pcbaProcessId, status, paramsStatusDeclare, paramsStatusActual, paramsStatusBase, begin, pageSize, companyIdList);
            for (PcbaLine pcbaLine : list) {
                pcbaLine.setLineLevel(lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevel()));
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                pcbaLine.setPcbaDeviceNums(pcbaDeviceList.size());
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    if (pcbaDevice.getProductTime() != null && !"".equals(pcbaDevice.getProductTime().toString())) {
                        Date d1 = new Date();
                        LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        LocalDate ld2 = pcbaDevice.getProductTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        double age = CommonUtils.calculateYearDifference(ld2, ld1);
                        pcbaDevice.setAge(age);

                        Result result = coreAlgorithmService.calcIsOverSixYearInHighLine(pcbaDevice, pcbaLine.getPcbaLineLevel());
                        if (result.getCode() == 200) {
                            pcbaDevice.setIsOverSixYearInHighLine(Integer.parseInt(result.getData().toString()));
                        }
                    }
                    PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                    if (pcbaDeviceResource != null) {
                        pcbaDeviceResource.setBrand(brandDao.getBrandById(pcbaDeviceResource.getBrandId()));
                        pcbaDeviceResource.setBrandType(brandTypeDao.getBrandTypeById(pcbaDeviceResource.getBrandTypeId()));
                        pcbaDevice.setPcbaDeviceResource(pcbaDeviceResource);
                        pcbaDevice.setPcbaDeviceType(pcbaDeviceTypeDao.getById(pcbaDevice.getPcbaDeviceTypeId()));

                    /*List<PcbaDeviceRelatedDeviceParam> pcbaDeviceRelatedDeviceParamList = pcbaDeviceRelatedDeviceParamDao.getAllByDeviceResourceId(pcbaDeviceResource.getPcbaDeviceResourceId());
                    for (PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam : pcbaDeviceRelatedDeviceParamList) {
                        pcbaDeviceRelatedDeviceParam.setPcbaDeviceParam(pcbaDeviceParamDao.getPcbaDeviceParamByKey(pcbaDeviceRelatedDeviceParam.getPcbaDeviceParamKey()));
                    }
                    List<PcbaDeviceRelatedTechParam> pcbaDeviceRelatedTechParamList = pcbaDeviceRelatedTechParamDao.getAllByDeviceResourceId(pcbaDeviceResource.getPcbaDeviceResourceId());
                    for (PcbaDeviceRelatedTechParam pcbaDeviceRelatedTechParam : pcbaDeviceRelatedTechParamList) {
                        pcbaDeviceRelatedTechParam.setTechDeviceParam(techDeviceParamDao.getTechDeviceParamByKey(pcbaDeviceRelatedTechParam.getTechDeviceParamKey()));
                    }
                    pcbaDevice.setPcbaDeviceRelatedDeviceParamList(pcbaDeviceRelatedDeviceParamList);
                    pcbaDevice.setPcbaDeviceRelatedTechParamList(pcbaDeviceRelatedTechParamList);*/
                    }
                }
                pcbaLine.setPcbaDeviceList(pcbaDeviceList);
                PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId());
                PcbaWorkshop pcbaWorkshop = pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId());
                PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId());
                pcbaLine.setPcbaCompany(pcbaCompany);
                pcbaLine.setPcbaWorkshop(pcbaWorkshop);
                pcbaLine.setPcbaProcess(pcbaProcess);

                // 判断该线体下的所有设备是否填写工艺实际能力
                Integer isFilled = 1;
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    if (pcbaDevice.getIsFilledTechParamsActual() == null || pcbaDevice.getIsFilledTechParamsActual() != 1) {
                        isFilled = 2;
                        break;
                    }
                }
                pcbaLine.setTechParamFilledStatus(isFilled);
            }
            List<PcbaLine> list2 = pcbaLineDao.getAllPcbaLine(searchPcbaLineName, pcbaCompanyId, pcbaWorkshopId, pcbaProcessId, status, paramsStatusDeclare, paramsStatusActual, paramsStatusBase, null, null, companyIdList);
            return ResultUtil.tableSuccess(page, pageSize, list2.size(), list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getAllPcbaLineForBaseLineCapacity(String searchPcbaLineName, Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId) {
        try {

            List<Integer> companyIdList = strToCompanys.getPcbaCompanyIdListFromStr();

            List<PcbaLine> allPcbaLine_all = pcbaLineDao.getAllPcbaLineForPcba(null, pcbaCompanyId, pcbaWorkshopId, pcbaProcessId, 1, null, 1, null, null, companyIdList);
            List<PcbaLine> allPcbaLine = new ArrayList<>(); // 最终符合条件的线体

            // 过滤掉 线体中 基线资源和工艺资源及设备实际能力认证都正常才返回
            for (PcbaLine pcbaLine : allPcbaLine_all) {
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                boolean flag = true;
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                    //if((pcbaDeviceResource.getAuditStatusBase() != null && pcbaDeviceResource.getAuditStatusBase() != 1) || (pcbaDeviceResource.getAuditStatusTech() != null && pcbaDeviceResource.getAuditStatusTech() != 1) || (pcbaDevice.getParamsStatus() != null && pcbaDevice.getParamsStatus() != 1)){
                    if ((pcbaDeviceResource.getAuditStatusBase() != null && pcbaDeviceResource.getAuditStatusBase() != 1)) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    allPcbaLine.add(pcbaLine);
                }
            }

            for (PcbaLine pcbaLine : allPcbaLine) {
                pcbaLine.setLineLevel(lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevel()));
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                pcbaLine.setPcbaDeviceNums(pcbaDeviceList.size());
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    if (pcbaDevice.getProductTime() != null && !"".equals(pcbaDevice.getProductTime().toString())) {
                        Date d1 = new Date();
                        LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        LocalDate ld2 = pcbaDevice.getProductTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        double age = CommonUtils.calculateYearDifference(ld2, ld1);
                        pcbaDevice.setAge(age);

                        Result result = coreAlgorithmService.calcIsOverSixYearInHighLine(pcbaDevice, pcbaLine.getPcbaLineLevel());
                        if (result.getCode() == 200) {
                            pcbaDevice.setIsOverSixYearInHighLine(Integer.parseInt(result.getData().toString()));
                        }
                    }
                    PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                    if (pcbaDeviceResource != null) {
                        pcbaDeviceResource.setBrand(brandDao.getBrandById(pcbaDeviceResource.getBrandId()));
                        pcbaDeviceResource.setBrandType(brandTypeDao.getBrandTypeById(pcbaDeviceResource.getBrandTypeId()));
                        pcbaDevice.setPcbaDeviceResource(pcbaDeviceResource);
                        pcbaDevice.setPcbaDeviceType(pcbaDeviceTypeDao.getById(pcbaDevice.getPcbaDeviceTypeId()));
                    }
                }
                pcbaLine.setPcbaDeviceList(pcbaDeviceList);
                PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId());
                PcbaWorkshop pcbaWorkshop = pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId());
                PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId());
                pcbaLine.setPcbaCompany(pcbaCompany);
                pcbaLine.setPcbaWorkshop(pcbaWorkshop);
                pcbaLine.setPcbaProcess(pcbaProcess);

                // 判断该线体下的所有设备是否填写工艺实际能力
                Integer isFilled = 1;
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    if (pcbaDevice.getIsFilledTechParamsActual() == null || pcbaDevice.getIsFilledTechParamsActual() != 1) {
                        isFilled = 2;
                        break;
                    }
                }
                pcbaLine.setTechParamFilledStatus(isFilled);
            }
            return ResultUtil.success(allPcbaLine);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getAllPcbaLineForTechLineCapacity(String searchPcbaLineName, Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId) {
        try {
            List<Integer> companyIdList = strToCompanys.getPcbaCompanyIdListFromStr();
            List<PcbaLine> allPcbaLine_all = pcbaLineDao.getAllOkLine(searchPcbaLineName, pcbaCompanyId, pcbaWorkshopId, pcbaProcessId, 1, companyIdList);
            for (PcbaLine pcbaLine : allPcbaLine_all) {
                pcbaLine.setLineLevel(lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevel()));
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                pcbaLine.setPcbaDeviceNums(pcbaDeviceList.size());
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    if (pcbaDevice.getProductTime() != null && !"".equals(pcbaDevice.getProductTime().toString())) {
                        Date d1 = new Date();
                        LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        LocalDate ld2 = pcbaDevice.getProductTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        double age = CommonUtils.calculateYearDifference(ld2, ld1);
                        pcbaDevice.setAge(age);

                        Result result = coreAlgorithmService.calcIsOverSixYearInHighLine(pcbaDevice, pcbaLine.getPcbaLineLevel());
                        if (result.getCode() == 200) {
                            pcbaDevice.setIsOverSixYearInHighLine(Integer.parseInt(result.getData().toString()));
                        }
                    }
                    PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                    if (pcbaDeviceResource != null) {
                        pcbaDeviceResource.setBrand(brandDao.getBrandById(pcbaDeviceResource.getBrandId()));
                        pcbaDeviceResource.setBrandType(brandTypeDao.getBrandTypeById(pcbaDeviceResource.getBrandTypeId()));
                        pcbaDevice.setPcbaDeviceResource(pcbaDeviceResource);
                        pcbaDevice.setPcbaDeviceType(pcbaDeviceTypeDao.getById(pcbaDevice.getPcbaDeviceTypeId()));
                    }
                }
                pcbaLine.setPcbaDeviceList(pcbaDeviceList);
                PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId());
                PcbaWorkshop pcbaWorkshop = pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId());
                PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId());
                pcbaLine.setPcbaCompany(pcbaCompany);
                pcbaLine.setPcbaWorkshop(pcbaWorkshop);
                pcbaLine.setPcbaProcess(pcbaProcess);

                /*// 判断该线体下的所有设备是否填写工艺实际能力
                Integer isFilled = 1;
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    if(pcbaDevice.getIsFilledTechParamsActual() == null || pcbaDevice.getIsFilledTechParamsActual() != 1){
                        isFilled = 2;
                        break;
                    }
                }
                pcbaLine.setTechParamFilledStatus(isFilled);*/
            }
            return ResultUtil.success(allPcbaLine_all);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getAllSmtLineByCompanyAndWorkshop(Integer pcbaCompanyId, Integer pcbaWorkshopId) {
        try {
            if (pcbaCompanyId == null || "".equals(pcbaCompanyId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaCompanyId", "Miss Param pcbaCompanyId", null);
            }
            if (pcbaWorkshopId == null || "".equals(pcbaWorkshopId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaWorkshopId", "Miss Param pcbaWorkshopId", null);
            }
            return ResultUtil.success(pcbaLineDao.getAllSmtLineByCompanyAndWorkshop(pcbaCompanyId, pcbaWorkshopId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getAllPcbaLineWithAuditDevice(String searchPcbaLineName, Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId, Integer status, Integer paramsStatus) {
        try {
            if (paramsStatus == null || "".equals(paramsStatus.toString())) {
                return ResultUtil.error(500, "错误参数paramsStatus", "Error Param paramsStatus", null);
            }

            List<PcbaLine> list = pcbaLineDao.getAllPcbaLineWithAuditDevice(searchPcbaLineName, pcbaCompanyId, pcbaWorkshopId, pcbaProcessId, status);
            List<PcbaLine> listWithAuditDevice = new ArrayList<>();
            for (PcbaLine pcbaLine : list) {
                pcbaLine.setLineLevel(lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevel()));
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                List<PcbaDevice> pcbaDeviceListWithAudit = new ArrayList<>();
                pcbaLine.setPcbaDeviceNums(pcbaDeviceList.size());
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    if (pcbaDevice.getParamsStatus() != null && pcbaDevice.getParamsStatus() == 3) {
                        PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                        if (pcbaDeviceResource != null) {
                            pcbaDeviceResource.setBrand(brandDao.getBrandById(pcbaDeviceResource.getBrandId()));
                            pcbaDeviceResource.setBrandType(brandTypeDao.getBrandTypeById(pcbaDeviceResource.getBrandTypeId()));
                            pcbaDevice.setPcbaDeviceResource(pcbaDeviceResource);
                            pcbaDevice.setPcbaDeviceType(pcbaDeviceTypeDao.getById(pcbaDevice.getPcbaDeviceTypeId()));
                        }
                        pcbaDeviceListWithAudit.add(pcbaDevice);
                    }

                }
                if (pcbaDeviceListWithAudit.size() > 0) {
                    pcbaLine.setPcbaDeviceList(pcbaDeviceListWithAudit);
                    PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId());
                    PcbaWorkshop pcbaWorkshop = pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId());
                    PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId());
                    pcbaLine.setPcbaCompany(pcbaCompany);
                    pcbaLine.setPcbaWorkshop(pcbaWorkshop);
                    pcbaLine.setPcbaProcess(pcbaProcess);

                    listWithAuditDevice.add(pcbaLine);
                }
            }
            return ResultUtil.success(listWithAuditDevice);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getAllPcbaLineView(String data) {
        try {

            JSONObject jsonObject = JSONObject.parseObject(data);
            String page = jsonObject.getString("page");
            String pageSize = jsonObject.getString("pageSize");
            String pcbaLineNames = jsonObject.getString("pcbaLineNames");
            String chooseCompanyAndWorkshop = jsonObject.getString("chooseCompanyAndWorkshop");
            String pcbaProcessIds = jsonObject.getString("pcbaProcessIds");
            String status = jsonObject.getString("status");

            if (page == null || !CommonUtils.isNumeric(page)) {
                return ResultUtil.error(500, "错误参数page", "Error Param page", null);
            }
            if (pageSize == null || !CommonUtils.isNumeric(pageSize)) {
                return ResultUtil.error(500, "错误参数pageSize", "Error Param pageSize", null);
            }
            List<Integer> companyIdList = strToCompanys.getPcbaCompanyIdListFromStr();
            int begin = (Integer.parseInt(page) - 1) * Integer.parseInt(pageSize);
            List<String> pbcaLineNameList = new ArrayList<>();
            List<String> pcbaWorkshopIdList = new ArrayList<>();
            List<String> pcbaProcessIdList = new ArrayList<>();
            if (pcbaLineNames != null && !"".equals(pcbaLineNames)) {
                String[] split = pcbaLineNames.split(",");
                pbcaLineNameList.addAll(Arrays.asList(split));
            }
            if (chooseCompanyAndWorkshop != null && !"".equals(chooseCompanyAndWorkshop)) {
                JSONArray jsonArray = JSONArray.parseArray(chooseCompanyAndWorkshop);
                for (int a = 0; a < jsonArray.size(); a++) {
                    JSONArray jsonArray1 = jsonArray.getJSONArray(a);
                    if (jsonArray1.size() == 2) {
                        pcbaWorkshopIdList.add(jsonArray1.get(1).toString());
                    }
                }

            }
            if (pcbaProcessIds != null && !"".equals(pcbaProcessIds)) {
                String[] split = pcbaProcessIds.split(",");
                pcbaProcessIdList.addAll(Arrays.asList(split));
            }
            List<PcbaLine> list = pcbaLineDao.getAllPcbaLineViewNew(pbcaLineNameList, pcbaWorkshopIdList, pcbaProcessIdList, 1, begin, Integer.parseInt(pageSize), companyIdList);
            for (PcbaLine pcbaLine : list) {
                pcbaLine.setLineLevel(lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevel()));
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                pcbaLine.setPcbaDeviceNums(pcbaDeviceList.size());
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {

                    if (pcbaDevice.getProductTime() != null && !"".equals(pcbaDevice.getProductTime().toString())) {
                        Date d1 = new Date();
                        LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        LocalDate ld2 = pcbaDevice.getProductTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        double age = CommonUtils.calculateYearDifference(ld2, ld1);
                        pcbaDevice.setAge(age);

                        Result result = coreAlgorithmService.calcIsOverSixYearInHighLine(pcbaDevice, pcbaLine.getPcbaLineLevel());
                        if (result.getCode() == 200) {
                            int i = Integer.parseInt(result.getData().toString());
                            pcbaDevice.setIsOverSixYearInHighLine(i);
                        }
                    }
                    PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                    if (pcbaDeviceResource != null) {
                        pcbaDeviceResource.setBrand(brandDao.getBrandById(pcbaDeviceResource.getBrandId()));
                        pcbaDeviceResource.setBrandType(brandTypeDao.getBrandTypeById(pcbaDeviceResource.getBrandTypeId()));
                        pcbaDevice.setPcbaDeviceResource(pcbaDeviceResource);

                        PcbaDeviceType pcbaDeviceType = pcbaDeviceTypeDao.getById(pcbaDevice.getPcbaDeviceTypeId());
                        if (pcbaDeviceType != null) {
                            if (pcbaDeviceType.getDevicePicture() != null && !"".equals(pcbaDeviceType.getDevicePicture())) {
                                if (env != null && env.contains("pro"))  {
                                    //pcbaDeviceType.setDevicePictureBase64(CommonUtils.base64Prefix() + CommonUtils.getImageBase64FromUrl(url + "/" + fileBucket + "/" + pcbaDeviceType.getDevicePicture()));
                                    List<Base64> base64ByTypeAndOuterId = base64Dao.getBase64ByTypeAndOuterId(1, pcbaDeviceType.getPcbaDeviceTypeId());
                                    if(base64ByTypeAndOuterId != null && base64ByTypeAndOuterId.size() > 0){
                                        String base64 = base64ByTypeAndOuterId.get(0).getBase64();
                                        if(base64 != null && !"".equals(base64)){
                                            pcbaDeviceType.setDevicePictureBase64(base64);
                                        }
                                    }
                                } else {
                                    List<Base64> base64ByTypeAndOuterId = base64Dao.getBase64ByTypeAndOuterId(1, pcbaDeviceType.getPcbaDeviceTypeId());
                                    if(base64ByTypeAndOuterId != null && base64ByTypeAndOuterId.size() > 0){
                                        String base64 = base64ByTypeAndOuterId.get(0).getBase64();
                                        if(base64 != null && !"".equals(base64)){
                                            pcbaDeviceType.setDevicePictureBase64(base64);
                                        }
                                    }
                                    //pcbaDeviceType.setDevicePictureBase64(CommonUtils.base64Prefix() + CommonUtils.getImageBase64FromUrl(CommonUtils.returnHostPrefixUrl() + pcbaDeviceType.getDevicePicture()));
                                }
                            }
                        }

                        pcbaDevice.setPcbaDeviceType(pcbaDeviceType);
                    }
                }
                int isOverSixYearInHighLine = 2;
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    if (pcbaDevice.getIsOverSixYearInHighLine() != null && pcbaDevice.getIsOverSixYearInHighLine() == 1) {
                        isOverSixYearInHighLine = 1;
                        break;
                    }
                }
                pcbaLine.setPcbaDeviceList(pcbaDeviceList);
                pcbaLine.setIsOverSixYearInHighLine(isOverSixYearInHighLine);
                PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId());
                PcbaWorkshop pcbaWorkshop = pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId());
                PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId());
                pcbaLine.setPcbaCompany(pcbaCompany);
                pcbaLine.setPcbaWorkshop(pcbaWorkshop);
                pcbaLine.setPcbaProcess(pcbaProcess);
            }
            Integer total = pcbaLineDao.getAllPcbaLineViewCountNew(pbcaLineNameList, pcbaWorkshopIdList, pcbaProcessIdList, 1, null, null, companyIdList);
            return ResultUtil.tableSuccess(Integer.parseInt(page), Integer.parseInt(pageSize), total, list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Transactional(transactionManager = "MysqlTransactionManager1")
    @Override
    public Result deleteById(Integer pcbaLineId) {
        try {
            if (pcbaLineId == null || "".equals(pcbaLineId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaLineId", "Miss Param pcbaLineId", null);
            }

            String userId = UserHeaderHolder.getUserId();
            PcbaLine oldPcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);

            pcbaLineDao.deleteById(pcbaLineId);
            //同时删除线体中的设备
            pcbaDeviceDao.deleteByPcbaLineId(pcbaLineId);

            // 操作日志
            operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 2, 1, new Date(), JSONObject.toJSONString(oldPcbaLine), null));

            return ResultUtil.success(null);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Transactional(transactionManager = "MysqlTransactionManager1")
    @Override
    public Result addOrUpdatePcbaLine(String data) {
        try {

            String userId = UserHeaderHolder.getUserId();

            JSONObject jsonObject = JSONObject.parseObject(data);
            String mode = jsonObject.getString("mode");
            JSONObject pcbaLineObj = jsonObject.getJSONObject("pcbaLine");
            if ("add".equals(mode)) {
                //add
                Date d = new Date();
                //1.新增线体
                PcbaLine addPcbaLine = new PcbaLine();
                addPcbaLine.setPcbaLineNameCn(pcbaLineObj.get("pcbaLineNameCn").toString());
                addPcbaLine.setPcbaLineNameEn(pcbaLineObj.get("pcbaLineNameEn").toString());
                addPcbaLine.setNotes(pcbaLineObj.get("notes").toString());
                addPcbaLine.setPcbaCompanyId(pcbaLineObj.getInteger("pcbaCompanyId"));
                addPcbaLine.setPcbaWorkshopId(pcbaLineObj.getInteger("pcbaWorkshopId"));
                addPcbaLine.setPcbaProcessId(pcbaLineObj.getInteger("pcbaProcessId"));
                addPcbaLine.setPcbaLineType(pcbaLineObj.getInteger("pcbaLineType"));
                addPcbaLine.setPcbaLineLevel(pcbaLineObj.getInteger("pcbaLineLevel"));
                addPcbaLine.setIsFirstCreate(pcbaLineObj.get("isFirstCreate") != null ? pcbaLineObj.getInteger("isFirstCreate") : 1);
                addPcbaLine.setCreateTime(d);
                addPcbaLine.setSort(pcbaLineObj.getInteger("sort"));
                addPcbaLine.setStatus(3);
                addPcbaLine.setParamsStatusDeclare(4);
                addPcbaLine.setParamsStatusActual(4);
                addPcbaLine.setIsFilledDeclare(2);
                addPcbaLine.setIsFilledActual(2);
                addPcbaLine.setParamsStatusBase(4);
                addPcbaLine.setFinalStatus(2);
                pcbaLineDao.addPcbaLine(addPcbaLine);

                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 1, 1, new Date(), null, JSONObject.toJSONString(addPcbaLine)));

                JSONArray jsonArray = pcbaLineObj.getJSONArray("setDevicesList");
                int index = 0;
                for (Object o : jsonArray) {
                    JSONObject jo = JSONObject.parseObject(o.toString());
                    Integer pcbaDeviceTypeId = Integer.parseInt(jo.get("pcbaDeviceTypeId").toString());
                    Integer pcbaDeviceResourceId = Integer.parseInt(jo.get("pcbaDeviceResourceId").toString());
                    Integer nums = Integer.parseInt(jo.get("nums").toString());

                    List<PcbaDevice> pcbaDeviceList = new ArrayList<>();

                    for (int a = 0; a < nums; a++) {
                        index++;
                        // 拿到上面的线体id，新增 设备
                        PcbaDevice addPcbaDevice = new PcbaDevice();
                        addPcbaDevice.setCreateTime(d);
                        addPcbaDevice.setStatus(3);
                        addPcbaDevice.setPcbaDeviceTypeId(pcbaDeviceTypeId);
                        addPcbaDevice.setSort(index);
                        addPcbaDevice.setPcbaLineId(addPcbaLine.getPcbaLineId());
                        addPcbaDevice.setPcbaDeviceResourceId(pcbaDeviceResourceId);
                        addPcbaDevice.setIsFilledTechParamsActual(2);
                        addPcbaDevice.setIsFilledUpkeep(2);
                        addPcbaDevice.setUpkeepStatus(1);
                        pcbaDeviceDao.addPcbaDevice(addPcbaDevice);

                        pcbaDeviceList.add(addPcbaDevice);
                    }

                    // 操作日志
                    operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 1, 1, new Date(), null, JSONObject.toJSONString(pcbaDeviceList)));
                }
                return ResultUtil.success(null);
            }/*else if("update".equals(mode)){
                //update
                Integer pcbaLineId = pcbaLineObj.getInteger("pcbaLineId");
                if(pcbaLineId == null || "".equals(pcbaLineId.toString())){
                    return ResultUtil.error(500, "缺少参数pcbaLineId", "Miss Param pcbaLineId", null);
                }
                Date d = new Date();
                PcbaLine updatePcbaLine = new PcbaLine();
                updatePcbaLine.setPcbaLineNameCn(pcbaLineObj.get("pcbaLineNameCn").toString());
                updatePcbaLine.setPcbaLineNameEn(pcbaLineObj.get("pcbaLineNameEn").toString());
                updatePcbaLine.setPcbaCompanyId(pcbaLineObj.getInteger("pcbaCompanyId"));
                updatePcbaLine.setPcbaWorkshopId(pcbaLineObj.getInteger("pcbaWorkshopId"));
                updatePcbaLine.setPcbaProcessId(pcbaLineObj.getInteger("pcbaProcessId"));
                updatePcbaLine.setPcbaLineType(pcbaLineObj.getInteger("pcbaLineType"));
                updatePcbaLine.setUpdateTime(d);
                updatePcbaLine.setSort(pcbaLineObj.getInteger("sort"));
                updatePcbaLine.setPcbaLineId(pcbaLineId);
                updatePcbaLine.setStatus(3);
                pcbaLineDao.updatePcbaLine(updatePcbaLine);
                //删除原先的related
                //pcbaLineRelatedDeviceResourceDao.deleteByLineId(pcbaLineId);
                //新增新的
                JSONArray jsonArray = pcbaLineObj.getJSONArray("devices");
                // Object[] objectArray = jsonArray.toArray();
                List<Integer> deviceIdsList = new ArrayList<>();
                if("1".equals(pcbaLineObj.getInteger("pcbaLineType").toString())){
                    //二维数组
                    for(int i=0;i<jsonArray.size();i++){
                        JSONArray objectArray = (JSONArray) jsonArray.get(i);
                        deviceIdsList.add(Integer.parseInt(objectArray.get(1).toString()));
                    }
                }else{
                    //一维数组
                    deviceIdsList.add(Integer.parseInt(jsonArray.get(1).toString()));
                }

                Integer[] deviceIds = deviceIdsList.toArray(new Integer[deviceIdsList.size()]);
                //Integer[] deviceIds = Arrays.copyOf(objectArray, objectArray.length, Integer[].class);
                for(int a = 0;a < deviceIds.length;a++){
                    PcbaDeviceResource p = pcbaDeviceResourceDao.getById(deviceIds[a]);
                    PcbaLineRelatedDeviceResource addPcbaLineRelatedDeviceResource = new PcbaLineRelatedDeviceResource();
                    addPcbaLineRelatedDeviceResource.setPcbaDeviceResourceId(deviceIds[a]);
                    addPcbaLineRelatedDeviceResource.setPcbaLineId(pcbaLineId);
                    addPcbaLineRelatedDeviceResource.setCreateTime(d);
                    addPcbaLineRelatedDeviceResource.setBrandId(p.getBrandId());
                    addPcbaLineRelatedDeviceResource.setBrandTypeId(p.getBrandTypeId());
                    addPcbaLineRelatedDeviceResource.setSort(a + 1);
                    addPcbaLineRelatedDeviceResource.setStatus(3);
                    //pcbaLineRelatedDeviceResourceDao.addPcbaLineRelatedDevice(addPcbaLineRelatedDeviceResource);
                }
                return ResultUtil.success(null);
            }*/
            return ResultUtil.error(500, "mode参数错误", "Error Param mode", null);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Transactional(transactionManager = "MysqlTransactionManager1")
    @Override
    public Result addPcbaDeviceResourceOfLine(String data) {
        String userId = UserHeaderHolder.getUserId();
        Date d = new Date();
        Integer pLineId = null;
        try {

            JSONObject jsonObject = JSONObject.parseObject(data);
            JSONObject pcbaLineObj = jsonObject.getJSONObject("pcbaLine");

            JSONArray jsonArray = pcbaLineObj.getJSONArray("setDevicesList");
            Integer pcbaLineId = Integer.parseInt(pcbaLineObj.get("pcbaLineId").toString());
            pLineId = pcbaLineId;
            // 查询当前线体的设备
            List<PcbaDevice> list = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLineId);
            int index = list.size() - 1;
            for (Object o : jsonArray) {
                JSONObject jo = JSONObject.parseObject(o.toString());
                Integer pcbaDeviceTypeId = Integer.parseInt(jo.get("pcbaDeviceTypeId").toString());
                Integer pcbaDeviceResourceId = Integer.parseInt(jo.get("pcbaDeviceResourceId").toString());
                Integer nums = Integer.parseInt(jo.get("nums").toString());

                for (int a = 0; a < nums; a++) {
                    index++;
                    // 拿到上面的线体id，新增 设备
                    PcbaDevice addPcbaDevice = new PcbaDevice();
                    addPcbaDevice.setCreateTime(d);
                    addPcbaDevice.setStatus(3);
                    addPcbaDevice.setPcbaDeviceTypeId(pcbaDeviceTypeId);
                    addPcbaDevice.setSort(index);
                    addPcbaDevice.setPcbaLineId(pcbaLineId);
                    addPcbaDevice.setPcbaDeviceResourceId(pcbaDeviceResourceId);
                    addPcbaDevice.setIsFilledTechParamsActual(2);
                    addPcbaDevice.setIsFilledUpkeep(2);
                    addPcbaDevice.setUpkeepStatus(1);
                    pcbaDeviceDao.addPcbaDevice(addPcbaDevice);

                    // 操作日志
                    operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 1, 1, new Date(), null, JSONObject.toJSONString(addPcbaDevice)));
                }
            }

            //新增/删除设备，填写资产信息 则会触发以下联动
            //   1）校验线体资产信息完整性
            //   2）线体基线整线能力认证状态、工艺整线实际能力认证状态改为`待提交审核`，其他情况不用变【功能已完成】

            // 1)
            PcbaLine oldPcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);
            // 线体状态改成初始化  status => 3
            PcbaLine pcbaLine = new PcbaLine();
            pcbaLine.setUpdateTime(new Date());
            pcbaLine.setPcbaLineId(pcbaLineId);
            pcbaLine.setStatus(3);
            pcbaLineDao.updatePcbaLine(pcbaLine);

            // 2)
            if (oldPcbaLine.getParamsStatusBase() != null && oldPcbaLine.getParamsStatusBase() == 1) {
                pcbaLineDao.auditPcbaLineParamBase(pcbaLineId, 4, "");
            }
            if (oldPcbaLine.getParamsStatusActual() != null && oldPcbaLine.getParamsStatusActual() == 1) {
                //pcbaLineDao.auditPcbaLineParamTechActual(pcbaLineId, 4, "");
            }
            //pcbaLineDao.updatePcbaLineLockDeclare(pcbaLineId, 2);

            // 级联触发 线体的最终状态
            coreAlgorithmService.cascadeUpdateLineFinalStatus(3, null, null, pcbaLineId);

            // 操作日志
            operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 1, new Date(), JSONObject.toJSONString(oldPcbaLine), JSONObject.toJSONString(pcbaLine)));

            return ResultUtil.success(null);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result judgeLineNameIsExist(Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId) {
        try {
            int nameNum = 20;
            List<MaintenanceConfig> maintenanceConfigByType = maintenanceConfigDao.getMaintenanceConfigByType(4);
            if (maintenanceConfigByType.size() > 0) {
                nameNum = Integer.parseInt(maintenanceConfigByType.get(0).getMaintenanceConfigValue());
            }
            List<Map<String, Object>> list = new ArrayList<>();
            PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(pcbaProcessId);
            if (pcbaProcess != null) {
                for (int a = 0; a < nameNum; a++) {
                    Map<String, Object> map = new HashMap<>();
                    String name = pcbaProcess.getPcbaProcessNameCn() + " " + (a + 1);
                    PcbaLine pcbaLine = pcbaLineDao.judgeLineNameIsExist(name, pcbaCompanyId, pcbaWorkshopId);
                    map.put("label", name);
                    map.put("value", name);
                    map.put("disabled", pcbaLine != null);
                    list.add(map);
                }
            }
            return ResultUtil.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result createLineListByProcess(Integer pcbaProcessId) {
        try {
            if (pcbaProcessId == null || "".equals(pcbaProcessId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaProcessId", "Miss Param pcbaProcessId", null);
            }
            int nameNum = 20;
            List<MaintenanceConfig> maintenanceConfigByType = maintenanceConfigDao.getMaintenanceConfigByType(4);
            if (maintenanceConfigByType.size() > 0) {
                nameNum = Integer.parseInt(maintenanceConfigByType.get(0).getMaintenanceConfigValue());
            }
            List<Map<String, Object>> list = new ArrayList<>();
            PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(pcbaProcessId);
            if (pcbaProcess != null) {
                for (int a = 0; a < nameNum; a++) {
                    Map<String, Object> map = new HashMap<>();
                    String name = pcbaProcess.getPcbaProcessNameCn() + " " + (a + 1);
                    map.put("label", name);
                    map.put("value", name);
                    list.add(map);
                }
            }
            return ResultUtil.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result createLineListByProcesses(String pcbaProcessIds) {
        try {
            if (pcbaProcessIds == null || "".equals(pcbaProcessIds)) {
                return ResultUtil.error(500, "缺少参数pcbaProcessIds", "Miss Param pcbaProcessIds", null);
            }
            String[] pcbaProcessIdArr = pcbaProcessIds.split(",");

            int nameNum = 20;
            List<MaintenanceConfig> maintenanceConfigByType = maintenanceConfigDao.getMaintenanceConfigByType(4);
            if (maintenanceConfigByType.size() > 0) {
                nameNum = Integer.parseInt(maintenanceConfigByType.get(0).getMaintenanceConfigValue());
            }
            List<Map<String, Object>> list = new ArrayList<>();
            for (String pcbaProcessId : pcbaProcessIdArr) {
                PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(Integer.parseInt(pcbaProcessId));
                if (pcbaProcess != null) {
                    for (int a = 0; a < nameNum; a++) {
                        Map<String, Object> map = new HashMap<>();
                        String name = pcbaProcess.getPcbaProcessNameCn() + " " + (a + 1);
                        map.put("label", name);
                        map.put("value", name);
                        list.add(map);
                    }
                }
            }
            return ResultUtil.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result updateLineLevel(Integer pcbaLineLevel, Integer pcbaLineId) {
        try {
            if (pcbaLineLevel == null || "".equals(pcbaLineLevel.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaLineLevel", "Miss Param pcbaLineLevel", null);
            }
            if (pcbaLineId == null || "".equals(pcbaLineId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaLineId", "Miss Param pcbaLineId", null);
            }

            String userId = UserHeaderHolder.getUserId();
            PcbaLine oldPcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);

            Integer integer = pcbaLineDao.updateLineLevel(pcbaLineLevel, pcbaLineId, new Date());
            if (integer > 0) {

                PcbaLine newPcbaLine = new PcbaLine();
                newPcbaLine.setPcbaLineId(pcbaLineId);
                newPcbaLine.setPcbaLineLevel(pcbaLineLevel);

                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 1, new Date(), JSONObject.toJSONString(oldPcbaLine), JSONObject.toJSONString(newPcbaLine)));

                try {
                    //if(!oldPcbaLine.getPcbaLineType().equals(pcbaLineLevel)){
                    // 修改线体状态到待提交审核
                    pcbaLineDao.auditPcbaLineParamBase(pcbaLineId, 4, "");
                    //pcbaLineDao.auditPcbaLineParamTechActual(pcbaLineId, 4, "");
                    //}
                } catch (Exception e) {
                    e.printStackTrace();
                }

                // 级联触发 线体的最终状态
                coreAlgorithmService.cascadeUpdateLineFinalStatus(3, null, null, pcbaLineId);

                return ResultUtil.success(null);
            }
            return ResultUtil.error(500, "操作失败", "Operate Fail", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result updateLineNotes(String notes, Integer pcbaLineId) {
        try {
            if (pcbaLineId == null || "".equals(pcbaLineId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaLineId", "Miss Param pcbaLineId", null);
            }

            String userId = UserHeaderHolder.getUserId();
            PcbaLine oldPcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);

            Integer integer = pcbaLineDao.updateLineNotes(notes, pcbaLineId, new Date());
            if (integer > 0) {

                PcbaLine newPcbaLine = new PcbaLine();
                newPcbaLine.setPcbaLineId(pcbaLineId);
                newPcbaLine.setNotes(notes);

                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 1, new Date(), JSONObject.toJSONString(oldPcbaLine), JSONObject.toJSONString(newPcbaLine)));

                try {
                    if (!oldPcbaLine.getNotes().equals(notes)) {
                        // 修改线体状态到待提交审核
                        pcbaLineDao.auditPcbaLineParamBase(pcbaLineId, 4, "");
                        //pcbaLineDao.auditPcbaLineParamTechActual(pcbaLineId, 4, "");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

                // 级联触发 线体的最终状态
                coreAlgorithmService.cascadeUpdateLineFinalStatus(3, null, null, pcbaLineId);

                return ResultUtil.success(null);
            }
            return ResultUtil.error(500, "操作失败", "Operate Fail", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public PcbaLine getPcbaLineById(Integer pcbaLineId) {
        PcbaLine pcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);
        pcbaLine.setLineLevel(lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevel()));
        pcbaLine.setLineLevelAudit(lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevelAudit()));
        List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
        List<PcbaDeviceAudit> pcbaDeviceAuditList = pcbaDeviceAuditDao.getAllPcbaDeviceAuditByLine(pcbaLine.getPcbaLineId());
        for (PcbaDevice pcbaDevice : pcbaDeviceList) {
            if (pcbaDevice.getProductTime() != null && !"".equals(pcbaDevice.getProductTime().toString())) {
                Date d1 = new Date();
                LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                LocalDate ld2 = pcbaDevice.getProductTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                double age = CommonUtils.calculateYearDifference(ld2, ld1);
                pcbaDevice.setAge(age);

                Result result = coreAlgorithmService.calcIsOverSixYearInHighLine(pcbaDevice, pcbaLine.getPcbaLineLevel());
                if (result.getCode() == 200) {
                    pcbaDevice.setIsOverSixYearInHighLine(Integer.parseInt(result.getData().toString()));
                }

            }
            PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
            pcbaDeviceResource.setBrand(brandDao.getBrandById(pcbaDeviceResource.getBrandId()));
            pcbaDeviceResource.setBrandType(brandTypeDao.getBrandTypeById(pcbaDeviceResource.getBrandTypeId()));
            pcbaDevice.setPcbaDeviceResource(pcbaDeviceResource);
            PcbaDeviceType pcbaDeviceType = pcbaDeviceTypeDao.getById(pcbaDevice.getPcbaDeviceTypeId());
            /*if(pcbaDeviceType.getDevicePicture() != null && !"".equals(pcbaDeviceType.getDevicePicture())){
                if("h3c_pro".equals(env)){
                    pcbaDeviceType.setDevicePictureBase64(CommonUtils.base64Prefix() + CommonUtils.getImageBase64FromUrl(url + "/" + fileBucket + "/" + pcbaDeviceType.getDevicePicture()));
                }else{
                    pcbaDeviceType.setDevicePictureBase64(CommonUtils.base64Prefix() + CommonUtils.getImageBase64FromUrl(CommonUtils.returnHostPrefixUrl() + pcbaDeviceType.getDevicePicture()));
                }
            }*/
            pcbaDevice.setPcbaDeviceType(pcbaDeviceType);
        }
        for (PcbaDeviceAudit pcbaDevice : pcbaDeviceAuditList) {
            if (pcbaDevice.getProductTime() != null && !"".equals(pcbaDevice.getProductTime().toString())) {
                Date d1 = new Date();
                LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                LocalDate ld2 = pcbaDevice.getProductTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                double age = CommonUtils.calculateYearDifference(ld2, ld1);
                pcbaDevice.setAge(age);

            }
            PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
            pcbaDeviceResource.setBrand(brandDao.getBrandById(pcbaDeviceResource.getBrandId()));
            pcbaDeviceResource.setBrandType(brandTypeDao.getBrandTypeById(pcbaDeviceResource.getBrandTypeId()));
            pcbaDevice.setPcbaDeviceResource(pcbaDeviceResource);
            PcbaDeviceType pcbaDeviceType = pcbaDeviceTypeDao.getById(pcbaDevice.getPcbaDeviceTypeId());
            if (pcbaDeviceType.getDevicePicture() != null && !"".equals(pcbaDeviceType.getDevicePicture())) {
                if (env != null && env.contains("pro"))  {
                    //pcbaDeviceType.setDevicePictureBase64(CommonUtils.base64Prefix() + CommonUtils.getImageBase64FromUrl(url + "/" + fileBucket + "/" + pcbaDeviceType.getDevicePicture()));
                    List<Base64> base64ByTypeAndOuterId = base64Dao.getBase64ByTypeAndOuterId(1, pcbaDeviceType.getPcbaDeviceTypeId());
                    if(base64ByTypeAndOuterId != null && base64ByTypeAndOuterId.size() > 0){
                        String base64 = base64ByTypeAndOuterId.get(0).getBase64();
                        if(base64 != null && !"".equals(base64)){
                            pcbaDeviceType.setDevicePictureBase64(base64);
                        }
                    }
                } else {
                    pcbaDeviceType.setDevicePictureBase64(CommonUtils.base64Prefix() + CommonUtils.getImageBase64FromUrl(CommonUtils.returnHostPrefixUrl() + pcbaDeviceType.getDevicePicture()));
                }
            }
            pcbaDevice.setPcbaDeviceType(pcbaDeviceType);
        }
        pcbaLine.setPcbaDeviceList(pcbaDeviceList);
        pcbaLine.setPcbaDeviceAuditList(pcbaDeviceAuditList);
        PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId());
        PcbaWorkshop pcbaWorkshop = pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId());
        PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId());
        pcbaLine.setPcbaCompany(pcbaCompany);
        pcbaLine.setPcbaWorkshop(pcbaWorkshop);
        pcbaLine.setPcbaProcess(pcbaProcess);
        return pcbaLine;
    }

    @Override
    public Result exportBaseCapacityExcel(String pcbaLineIds) {
        try {
            if (pcbaLineIds == null || "".equals(pcbaLineIds)) {
                return ResultUtil.error(500, "缺少参数pcbaLineIds", "Miss Param pcbaLineIds", null);
            }

            String[] arr = pcbaLineIds.split(",");

            List<LineBaseBigType> allLineBaseBigTypeList = lineBaseBigTypeDao.getAllLineBaseBigType(null);
            for (LineBaseBigType lineBaseBigType : allLineBaseBigTypeList) {
                List<LineBaseSmallType> allLineBaseSmallTypeList = lineBaseSmallTypeDao.getAllLineBaseSmallTypeByBigType(null, lineBaseBigType.getLineBaseBigTypeId());
                for (LineBaseSmallType lineBaseSmallType : allLineBaseSmallTypeList) {
                    lineBaseSmallType.setPcbaProcess(pcbaProcessDao.getPcbaProcessById(lineBaseSmallType.getPcbaProcessId()));
                    lineBaseSmallType.setPcbaProcessSmt(pcbaProcessDao.getPcbaProcessById(lineBaseSmallType.getPcbaProcessIdSmt()));
                    List<BaseCapacityRule> allBaseCapacityRule = baseCapacityRuleDao.getAllBaseCapacityRule(null, lineBaseBigType.getLineBaseBigTypeId(), lineBaseSmallType.getLineBaseSmallTypeId());
                    lineBaseSmallType.setBaseCapacityRuleList(allBaseCapacityRule);
                }
                lineBaseBigType.setLineBaseSmallTypeList(allLineBaseSmallTypeList);
            }

            List<PcbaLine> list = new ArrayList<>();
            for (String s : arr) {
                PcbaLine pcbaLine = pcbaLineDao.getPcbaLineById(Integer.parseInt(s));
                pcbaLine.setPcbaCompany(pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId()));
                pcbaLine.setPcbaWorkshop(pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId()));
                pcbaLine.setPcbaProcess(pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId()));
                Result result = coreAlgorithmService.calcLineBaseCapacity(Integer.parseInt(s));
                if (result.getCode() == 200) {
                    //System.out.println((Map<String,Object>)result.getData());
                    pcbaLine.setBaseCapacityMap((Map<String, Object>) result.getData());
                }
                list.add(pcbaLine);
            }

            List<PcbaLine> SMTLine = new ArrayList<>();
            List<PcbaLine> NotSMTLine = new ArrayList<>();
            for (PcbaLine pcbaLine : list) {
                if ("SMT".equals(pcbaLine.getPcbaProcess().getPcbaProcessNameCn().toUpperCase())) {
                    pcbaLine.setLineBaseBigTypeList(allLineBaseBigTypeList);
                    SMTLine.add(pcbaLine);
                } else {
                    NotSMTLine.add(pcbaLine);
                }
            }

            // 将 非 SMT 的value 填充到 SMT 的空value
            // 若SMT线体中存在对应离线设备，则取SMT线体中此设备的值，否则取离线设备的值
            for (PcbaLine pcbaLine : SMTLine) {
                List<BaseCapacityRule> finalKeyAndValueList = new ArrayList<>();
                Map<String, Object> baseCapacityMap = pcbaLine.getBaseCapacityMap();
                List<BaseCapacityRule> finalKeyAndValueList1 = (List<BaseCapacityRule>) baseCapacityMap.get("finalKeyAndValueList");
                for (BaseCapacityRule baseCapacityRule : finalKeyAndValueList1) {
                    for (PcbaLine pcbaLine2 : NotSMTLine) {
                        Map<String, Object> baseCapacityMap2 = pcbaLine2.getBaseCapacityMap();
                        List<BaseCapacityRule> finalKeyAndValueList2 = (List<BaseCapacityRule>) baseCapacityMap2.get("finalKeyAndValueList");
                        for (BaseCapacityRule baseCapacityRule2 : finalKeyAndValueList2) {
                            if (baseCapacityRule.getLineBaseParamKey().equals(baseCapacityRule2.getLineBaseParamKey())) {
                                if ((baseCapacityRule.getLineBaseParamValue() == null || "".equals(baseCapacityRule.getLineBaseParamValue())) && baseCapacityRule2.getLineBaseParamValue() != null && !"".equals(baseCapacityRule2.getLineBaseParamValue())) {
                                    baseCapacityRule.setLineBaseParamValue(baseCapacityRule2.getLineBaseParamValue());
                                }
                                break;
                            }
                        }
                    }
                    finalKeyAndValueList.add(baseCapacityRule);
                }
                Map<String, Object> map = new HashMap<>();
                map.put("finalKeyAndValueList", finalKeyAndValueList1);
                pcbaLine.setBaseCapacityMap(map);
            }
            System.out.println(SMTLine);

            // 创建工作簿对象
            Workbook workbook = new XSSFWorkbook();
            String excelFileName = "线体设备整线能力反馈表";
            for (PcbaLine p : SMTLine) {
                int index = 0;
                int beginIndex1 = 1;
                int beginIndex2 = 1;
                //String excelName = p.getPcbaLineNameCn() + "(" + p.getPcbaCompany().getPcbaCompanyNameCn() + "-" + p.getPcbaWorkshop().getPcbaWorkshopNameCn() + ")";
                // XX工厂线体设备整线能力反馈报告
                String excelName = p.getPcbaCompany().getPcbaCompanyNameCn() + "工厂线体设备整线能力反馈报告（" + p.getPcbaLineNameCn() + "）";
                // 创建工作表对象
                Sheet sheet = workbook.createSheet(CommonUtils.handleSheetName(excelName));

                Map<String, Object> m = p.getBaseCapacityMap();
                // System.out.println(allLineBaseBigTypeList);
                // 带有数据的项目大类
                //List<LineBaseBigType> lineBaseBigTypeList = (List<LineBaseBigType>)m.get("lineBaseBigTypeList");
                //带有数据的所有参数项
                List<BaseCapacityRule> baseCapacityRules = (List<BaseCapacityRule>) m.get("finalKeyAndValueList");

                for (LineBaseBigType lineBaseBigType : allLineBaseBigTypeList) {
                    for (LineBaseSmallType lineBaseSmallType : lineBaseBigType.getLineBaseSmallTypeList()) {
                        for (BaseCapacityRule baseCapacityRule : lineBaseSmallType.getBaseCapacityRuleList()) {
                            for (BaseCapacityRule capacityRule : baseCapacityRules) {
                                if (baseCapacityRule.getLineBaseParamKey().equals(capacityRule.getLineBaseParamKey())) {
                                    baseCapacityRule.setLineBaseParamValue(capacityRule.getLineBaseParamValue());
                                    break;
                                }
                            }
                        }
                    }
                }

                    /*// 将 lineBaseBigTypeList  和 allLineBaseBigTypeList 对比，将不全的值补充为NA
                    for (LineBaseBigType lineBaseBigType : allLineBaseBigTypeList) {
                        for (LineBaseBigType lineBaseBigType2 : lineBaseBigTypeList) {
                            if(lineBaseBigType.getLineBaseBigTypeId().equals(lineBaseBigType2.getLineBaseBigTypeId())){
                                for (LineBaseSmallType lineBaseSmallType : lineBaseBigType.getLineBaseSmallTypeList()) {
                                    if(lineBaseBigType2.getLineBaseSmallTypeList() != null && lineBaseBigType2.getLineBaseSmallTypeList().size() > 0){
                                        for (LineBaseSmallType lineBaseSmallType2 : lineBaseBigType2.getLineBaseSmallTypeList()) {
                                            if(lineBaseSmallType.getLineBaseSmallTypeId().equals(lineBaseSmallType2.getLineBaseSmallTypeId())){
                                                for (BaseCapacityRule baseCapacityRule : lineBaseSmallType.getBaseCapacityRuleList()) {
                                                    if(lineBaseSmallType2.getBaseCapacityRuleList() != null && lineBaseSmallType2.getBaseCapacityRuleList().size() > 0){
                                                        for (BaseCapacityRule baseCapacityRule2 : lineBaseSmallType2.getBaseCapacityRuleList()) {
                                                            if(baseCapacityRule.getLineBaseParamKey().equals(baseCapacityRule2.getLineBaseParamKey())){
                                                                baseCapacityRule.setLineBaseParamValue(baseCapacityRule2.getLineBaseParamValue());
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }*/

                CellStyle bodyContextCellStyle = workbook.createCellStyle();
                DataFormat format = workbook.createDataFormat();
                bodyContextCellStyle.setDataFormat(format.getFormat("@"));
                bodyContextCellStyle.setBorderBottom(BorderStyle.THIN);
                bodyContextCellStyle.setBorderLeft(BorderStyle.THIN);
                bodyContextCellStyle.setBorderRight(BorderStyle.THIN);
                bodyContextCellStyle.setBorderTop(BorderStyle.THIN);
                bodyContextCellStyle.setAlignment(HorizontalAlignment.LEFT);
                bodyContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

                CellStyle titleContextCellStyle = workbook.createCellStyle();
                titleContextCellStyle.setBorderBottom(BorderStyle.THIN);
                titleContextCellStyle.setBorderLeft(BorderStyle.THIN);
                titleContextCellStyle.setBorderRight(BorderStyle.THIN);
                titleContextCellStyle.setBorderTop(BorderStyle.THIN);
                titleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
                titleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
                // 设置背景色为红色
                titleContextCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
                // 创建字体对象
                Font titleFont = workbook.createFont();
                // 设置字体颜色为蓝色
                titleFont.setColor(IndexedColors.WHITE.getIndex());
                titleFont.setBold(true);
                titleContextCellStyle.setFont(titleFont);
                // 设置填充类型为填充实体背景
                titleContextCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                Row row = sheet.createRow(0);
                Cell cell;

                List<Map<String, Object>> titleList = new ArrayList<>();
                Map<String, Object> map = new HashMap<>();
                map = new HashMap<>();
                map.put("title", "项目大类");
                map.put("width", 10000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "线体名称");
                map.put("width", 3000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "项目小类");
                map.put("width", 10000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "整线能力评估项");
                map.put("width", 15000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "基线能力反馈");
                map.put("width", 6000);
                titleList.add(map);
                row = sheet.createRow(0);
                for (int a = 0; a < titleList.size(); a++) {
                    sheet.setColumnWidth(a, Integer.parseInt(titleList.get(a).get("width").toString()));
                    // sheet.setDefaultRowHeight((short)450);
                    cell = row.createCell(a);
                    // 向单元格中写入数据
                    cell.setCellValue(titleList.get(a).get("title").toString());
                    cell.setCellStyle(titleContextCellStyle);
                }

                for (LineBaseBigType lineBaseBigType : allLineBaseBigTypeList) {
                    if (lineBaseBigType.getLineBaseSmallTypeList() != null && lineBaseBigType.getLineBaseSmallTypeList().size() > 0) {
                        for (LineBaseSmallType lineBaseSmallType : lineBaseBigType.getLineBaseSmallTypeList()) {
                            if (lineBaseSmallType.getBaseCapacityRuleList() != null && lineBaseSmallType.getBaseCapacityRuleList().size() > 0) {
                                for (BaseCapacityRule baseCapacityRule : lineBaseSmallType.getBaseCapacityRuleList()) {
                                    index++;
                                    Row row_ = sheet.createRow(index);

                                    // 项目大类
                                    Cell cell_ = row_.createCell(0);
                                    cell_.setCellValue(lineBaseBigType.getLineBaseBigTypeName());
                                    cell_.setCellStyle(bodyContextCellStyle);

                                    // 线体名称
                                    cell_ = row_.createCell(1);
                                    cell_.setCellValue(p.getPcbaLineNameCn());
                                    cell_.setCellStyle(bodyContextCellStyle);
                                    if (lineBaseSmallType.getPcbaProcess() != null && lineBaseSmallType.getPcbaProcess().getPcbaProcessNameCn() != null && !"".equals(lineBaseSmallType.getPcbaProcess().getPcbaProcessNameCn())) {
                                        if ("SMT".equals(lineBaseSmallType.getPcbaProcess().getPcbaProcessNameCn().toUpperCase())) {
                                            //boolean b = false;
                                            String n = "";
                                            for (PcbaLine notSmtP : NotSMTLine) {
                                                if ("SMT".equals(lineBaseSmallType.getPcbaProcessSmt().getPcbaProcessNameCn())) {
                                                    n = p.getPcbaLineNameCn();
                                                } else {
                                                    if (notSmtP.getPcbaProcess().getPcbaProcessNameCn().contains(lineBaseSmallType.getPcbaProcessSmt().getPcbaProcessNameCn())) {
                                                        n = notSmtP.getPcbaLineNameCn();
                                                        //b = true;
                                                        break;
                                                    }
                                                }
                                            }
                                            if (!"".equals(n)) {
                                                cell_.setCellValue(n);
                                                cell_.setCellStyle(bodyContextCellStyle);
                                            }
                                        } else {
                                            String n = "";
                                            for (PcbaLine notSmtP : NotSMTLine) {
                                                if (notSmtP.getPcbaProcess().getPcbaProcessNameCn().contains(lineBaseSmallType.getPcbaProcess().getPcbaProcessNameCn())) {
                                                    n = notSmtP.getPcbaLineNameCn();
                                                    break;
                                                }
                                            }
                                            cell_.setCellValue(n);
                                            cell_.setCellStyle(bodyContextCellStyle);
                                        }
                                    }

                                    // 项目小类
                                    cell_ = row_.createCell(2);
                                    cell_.setCellValue(lineBaseSmallType.getLineBaseSmallTypeName());
                                    cell_.setCellStyle(bodyContextCellStyle);

                                    // 整线能力评估项
                                    cell_ = row_.createCell(3);
                                    cell_.setCellValue(baseCapacityRule.getBaseCapacityRuleName());
                                    cell_.setCellStyle(bodyContextCellStyle);

                                    // 基线能力反馈
                                    cell_ = row_.createCell(4);
                                    cell_.setCellValue((baseCapacityRule.getLineBaseParamValue() != null && !"".equals(baseCapacityRule.getLineBaseParamValue())) ? baseCapacityRule.getLineBaseParamValue() : "");
                                    cell_.setCellStyle(bodyContextCellStyle);
                                }
                                if (lineBaseSmallType.getBaseCapacityRuleList().size() > 1) {
                                    if (index > beginIndex2) {
                                        sheet.addMergedRegion(new CellRangeAddress(beginIndex2, index, 2, 2));
                                        sheet.addMergedRegion(new CellRangeAddress(beginIndex2, index, 1, 1));
                                        beginIndex2 = index + 1;
                                    }
                                } else {
                                    beginIndex2 = index + 1;
                                }
                            }
                        }
                        //if(lineBaseBigType.getLineBaseSmallTypeList().size() > 1){
                        if (index > beginIndex1) {
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 0, 0));
                            beginIndex1 = index + 1;
                        }
                        /*}else{
                            beginIndex1 = index + 1;
                        }*/
                    }
                }
                /*if(index > 1){
                    sheet.addMergedRegion(new CellRangeAddress(1, index, 1, 1));
                }*/
            }
            String fileName = excelFileName + CommonUtils.getTimestamp() + ".xlsx";
            String pathPrefix = fileSaveUrl + "exportExcels\\";
            File folder = new File(pathPrefix);
            if (!folder.isDirectory()) {
                folder.mkdirs();
            }
            String filePath = pathPrefix + fileName;
            // 导出Excel文件
            FileOutputStream outputStream = new FileOutputStream(filePath);
            workbook.write(outputStream);
            workbook.close();
            outputStream.close();

            byte[] data = null;
            InputStream in = new FileInputStream(filePath);
            data = new byte[in.available()];
            in.read(data);
            in.close();
            java.util.Base64.Encoder encoder = java.util.Base64.getEncoder();
            String base64 = encoder.encodeToString(data);

            Map<String, Object> resMap = new HashMap<>();
            resMap.put("base64", base64);
            resMap.put("fileName", fileName);
            resMap.put("lineList", SMTLine);
            return ResultUtil.success(resMap);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result exportBaseCapacityExcelV2(String pcbaLineIds) {
        try {
            if (pcbaLineIds == null || "".equals(pcbaLineIds)) {
                return ResultUtil.error(500, "缺少参数pcbaLineIds", "Miss Param pcbaLineIds", null);
            }

            String[] arr = pcbaLineIds.split(",");

            List<PcbaLine> list = new ArrayList<>();
            for (String s : arr) {
                PcbaLine pcbaLine = pcbaLineDao.getPcbaLineById(Integer.parseInt(s));
                pcbaLine.setPcbaCompany(pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId()));
                pcbaLine.setPcbaWorkshop(pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId()));
                pcbaLine.setPcbaProcess(pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId()));
                Result result = coreAlgorithmService.calcLineBaseCapacity(Integer.parseInt(s));
                if (result.getCode() == 200) {
                    //System.out.println((Map<String,Object>)result.getData());
                    pcbaLine.setBaseCapacityMap((Map<String, Object>) result.getData());
                }
                list.add(pcbaLine);
            }

            // SMT线体
            List<PcbaLine> smtLineList = new ArrayList<>();
            // 非 SMT线体
            List<PcbaLine> otherLineList = new ArrayList<>();
            // 每个smt线体中包含的设备
            //List<Map<String, Object>> smtContainsDeviceTypeIdList = new ArrayList<>();
            // 非smt线体中包含的设备
            //List<PcbaDevice> otherContainsDeviceTypeIdList = new ArrayList<>();
            for (PcbaLine pcbaLine : list) {
                if (pcbaLine.getPcbaLineType() == 1) {
                    smtLineList.add(pcbaLine);
                } else {
                    //if(pcbaLine.getPcbaLineNameCn() != null && (!(pcbaLine.getPcbaLineNameCn().toUpperCase()).contains("PTH"))){
                    otherLineList.add(pcbaLine);
                    //}
                }
            }
//            for (PcbaLine pcbaLine : otherLineList) {
//                List<PcbaDevice> pcbaDevices = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
//                otherContainsDeviceTypeIdList.addAll(pcbaDevices);
//            }
//            for (PcbaLine pcbaLine : smtLineList) {
//                List<PcbaDevice> pcbaDevices = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
//                Integer pcbaLineId = pcbaLine.getPcbaLineId();
//                Map<String, Object> map = new HashMap<>();
//                map.put("pcbaLineId", pcbaLineId);
//                map.put("pcbaDevices", pcbaDevices);
//                smtContainsDeviceTypeIdList.add(map);
//            }

            List<LineBaseBigType> allLineBaseBigTypeList = lineBaseBigTypeDao.getAllLineBaseBigType(null);
            for (LineBaseBigType lineBaseBigType : allLineBaseBigTypeList) {
                List<LineBaseSmallType> allLineBaseSmallTypeList = lineBaseSmallTypeDao.getAllLineBaseSmallTypeByBigType(null, lineBaseBigType.getLineBaseBigTypeId());
                for (LineBaseSmallType lineBaseSmallType : allLineBaseSmallTypeList) {
                    lineBaseSmallType.setPcbaProcess(pcbaProcessDao.getPcbaProcessById(lineBaseSmallType.getPcbaProcessId()));
                    lineBaseSmallType.setPcbaProcessSmt(pcbaProcessDao.getPcbaProcessById(lineBaseSmallType.getPcbaProcessIdSmt()));
                    List<BaseCapacityRule> allBaseCapacityRule = baseCapacityRuleDao.getAllBaseCapacityRule(null, lineBaseBigType.getLineBaseBigTypeId(), lineBaseSmallType.getLineBaseSmallTypeId());
                    lineBaseSmallType.setBaseCapacityRuleList(allBaseCapacityRule);
                }
                lineBaseBigType.setLineBaseSmallTypeList(allLineBaseSmallTypeList);
            }

            // 将 非 SMT 的value 填充到 SMT 的空value
            // 若SMT线体中存在对应离线设备，则取SMT线体中此设备的值，否则取离线设备的值
            for (PcbaLine pcbaLine : smtLineList) {
                List<BaseCapacityRule> finalKeyAndValueList = new ArrayList<>();
                Map<String, Object> baseCapacityMap = pcbaLine.getBaseCapacityMap();
                List<BaseCapacityRule> finalKeyAndValueList1 = (List<BaseCapacityRule>) baseCapacityMap.get("finalKeyAndValueList");
                for (BaseCapacityRule baseCapacityRule : finalKeyAndValueList1) {
                    //System.out.println("baseCapacityRule===" + baseCapacityRule.getLineBaseParamValue());
                    //System.out.println("pcbaLine.getPcbaLineNameCn()===" + pcbaLine.getPcbaLineNameCn());
                    baseCapacityRule.setBaseLineValueFrom(pcbaLine.getPcbaLineNameCn());
                    for (PcbaLine pcbaLine2 : otherLineList) {
                        Map<String, Object> baseCapacityMap2 = pcbaLine2.getBaseCapacityMap();
                        List<BaseCapacityRule> finalKeyAndValueList2 = (List<BaseCapacityRule>) baseCapacityMap2.get("finalKeyAndValueList");
                        for (BaseCapacityRule baseCapacityRule2 : finalKeyAndValueList2) {
                            if (baseCapacityRule.getLineBaseParamKey().equals(baseCapacityRule2.getLineBaseParamKey())) {
                                if ((baseCapacityRule.getLineBaseParamValue() == null || "".equals(baseCapacityRule.getLineBaseParamValue())) && baseCapacityRule2.getLineBaseParamValue() != null && !"".equals(baseCapacityRule2.getLineBaseParamValue())) {
                                    baseCapacityRule.setLineBaseParamValue(baseCapacityRule2.getLineBaseParamValue());
                                    baseCapacityRule.setBaseLineValueFrom(pcbaLine2.getPcbaLineNameCn());
                                }
                                break;
                            }
                        }
                    }
                    finalKeyAndValueList.add(baseCapacityRule);
                }

                for (BaseCapacityRule baseCapacityRule : finalKeyAndValueList) {
                    if (baseCapacityRule.getLineBaseParamValue() == null || "".equals(baseCapacityRule.getLineBaseParamValue())) {
                        baseCapacityRule.setLineBaseParamValue("NA");
                        baseCapacityRule.setBaseLineValueFrom("NA");
                    }
                }

                Map<String, Object> map = new HashMap<>();
                map.put("finalKeyAndValueList", finalKeyAndValueList);
                pcbaLine.setBaseCapacityMap(map);
            }

            // 创建工作簿对象
            Workbook workbook = new XSSFWorkbook();
            String excelFileName = "线体设备整线能力反馈表";
            for (PcbaLine p : smtLineList) {
                int index = 0;
                int beginIndex1 = 1;
                int beginIndex2 = 1;
                //String excelName = p.getPcbaLineNameCn() + "(" + p.getPcbaCompany().getPcbaCompanyNameCn() + "-" + p.getPcbaWorkshop().getPcbaWorkshopNameCn() + ")";
                // XX工厂线体设备整线能力反馈报告
                String excelName = p.getPcbaCompany().getPcbaCompanyNameCn() + "工厂线体设备整线能力反馈报告（" + p.getPcbaLineNameCn() + "）";
                // 创建工作表对象
                Sheet sheet = workbook.createSheet(CommonUtils.handleSheetName(excelName));

                Map<String, Object> m = p.getBaseCapacityMap();
                // System.out.println(allLineBaseBigTypeList);
                // 带有数据的项目大类
                //List<LineBaseBigType> lineBaseBigTypeList = (List<LineBaseBigType>)m.get("lineBaseBigTypeList");
                //带有数据的所有参数项
                List<BaseCapacityRule> baseCapacityRules = (List<BaseCapacityRule>) m.get("finalKeyAndValueList");

                for (LineBaseBigType lineBaseBigType : allLineBaseBigTypeList) {
                    for (LineBaseSmallType lineBaseSmallType : lineBaseBigType.getLineBaseSmallTypeList()) {
                        for (BaseCapacityRule baseCapacityRule : lineBaseSmallType.getBaseCapacityRuleList()) {
                            for (BaseCapacityRule capacityRule : baseCapacityRules) {
                                if (baseCapacityRule.getLineBaseParamKey().equals(capacityRule.getLineBaseParamKey())) {
                                    baseCapacityRule.setLineBaseParamValue(capacityRule.getLineBaseParamValue());
                                    baseCapacityRule.setBaseLineValueFrom(capacityRule.getBaseLineValueFrom());
                                    break;
                                }
                            }
                        }
                    }
                }
                for (LineBaseBigType lineBaseBigType : allLineBaseBigTypeList) {
                    if (lineBaseBigType.getLineBaseSmallTypeList() != null && lineBaseBigType.getLineBaseSmallTypeList().size() > 0) {
                        for (LineBaseSmallType lineBaseSmallType : lineBaseBigType.getLineBaseSmallTypeList()) {
                            List<String> valueFromList = new ArrayList<>();
                            if (lineBaseSmallType.getBaseCapacityRuleList() != null && lineBaseSmallType.getBaseCapacityRuleList().size() > 0) {
                                for (BaseCapacityRule baseCapacityRule : lineBaseSmallType.getBaseCapacityRuleList()) {
                                    // 过滤重复的  和  NA
                                    if (!valueFromList.contains(baseCapacityRule.getBaseLineValueFrom()) && !"NA".equals(baseCapacityRule.getBaseLineValueFrom())) {
                                        valueFromList.add(baseCapacityRule.getBaseLineValueFrom());
                                    }
                                }
                            }
                            //System.out.println(valueFromList);
                            // valueFromList 长度为0 则渲染NA
                            // 长度不为0， 有SMT则渲染SMT,否则渲染其他
                            if (valueFromList.size() == 0) {
                                lineBaseSmallType.setBaseLineValueFrom("NA");
                            } else {
                                if (valueFromList.toString().contains("SMT")) {
                                    for (String s : valueFromList) {
                                        if (s.toUpperCase().contains("SMT")) {
                                            lineBaseSmallType.setBaseLineValueFrom(s);
                                            break;
                                        }
                                    }
                                } else {
                                    lineBaseSmallType.setBaseLineValueFrom(valueFromList.get(0));
                                }
                            }
                        }
                    }
                }

                CellStyle bodyContextCellStyle = workbook.createCellStyle();
                DataFormat format = workbook.createDataFormat();
                bodyContextCellStyle.setDataFormat(format.getFormat("@"));
                bodyContextCellStyle.setBorderBottom(BorderStyle.THIN);
                bodyContextCellStyle.setBorderLeft(BorderStyle.THIN);
                bodyContextCellStyle.setBorderRight(BorderStyle.THIN);
                bodyContextCellStyle.setBorderTop(BorderStyle.THIN);
                bodyContextCellStyle.setAlignment(HorizontalAlignment.LEFT);
                bodyContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

                CellStyle titleContextCellStyle = workbook.createCellStyle();
                titleContextCellStyle.setBorderBottom(BorderStyle.THIN);
                titleContextCellStyle.setBorderLeft(BorderStyle.THIN);
                titleContextCellStyle.setBorderRight(BorderStyle.THIN);
                titleContextCellStyle.setBorderTop(BorderStyle.THIN);
                titleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
                titleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
                // 设置背景色为红色
                titleContextCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
                // 创建字体对象
                Font titleFont = workbook.createFont();
                // 设置字体颜色为蓝色
                titleFont.setColor(IndexedColors.WHITE.getIndex());
                titleFont.setBold(true);
                titleContextCellStyle.setFont(titleFont);
                // 设置填充类型为填充实体背景
                titleContextCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                Row row = sheet.createRow(0);
                Cell cell;

                List<Map<String, Object>> titleList = new ArrayList<>();
                Map<String, Object> map = new HashMap<>();
                map = new HashMap<>();
                map.put("title", "项目大类");
                map.put("width", 10000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "线体名称");
                map.put("width", 5000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "项目小类");
                map.put("width", 10000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "整线能力评估项");
                map.put("width", 15000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "基线能力反馈");
                map.put("width", 6000);
                titleList.add(map);
                row = sheet.createRow(0);
                for (int a = 0; a < titleList.size(); a++) {
                    sheet.setColumnWidth(a, Integer.parseInt(titleList.get(a).get("width").toString()));
                    // sheet.setDefaultRowHeight((short)450);
                    cell = row.createCell(a);
                    // 向单元格中写入数据
                    cell.setCellValue(titleList.get(a).get("title").toString());
                    cell.setCellStyle(titleContextCellStyle);
                }

                for (LineBaseBigType lineBaseBigType : allLineBaseBigTypeList) {
                    if (lineBaseBigType.getLineBaseSmallTypeList() != null && lineBaseBigType.getLineBaseSmallTypeList().size() > 0) {
                        for (LineBaseSmallType lineBaseSmallType : lineBaseBigType.getLineBaseSmallTypeList()) {
                            if (lineBaseSmallType.getBaseCapacityRuleList() != null && lineBaseSmallType.getBaseCapacityRuleList().size() > 0) {
                                for (BaseCapacityRule baseCapacityRule : lineBaseSmallType.getBaseCapacityRuleList()) {
                                    index++;
                                    Row row_ = sheet.createRow(index);

                                    // 项目大类
                                    Cell cell_ = row_.createCell(0);
                                    cell_.setCellValue(lineBaseBigType.getLineBaseBigTypeName());
                                    cell_.setCellStyle(bodyContextCellStyle);

                                    // 线体名称
                                    cell_ = row_.createCell(1);
                                    // cell_.setCellValue(baseCapacityRule.getBaseLineValueFrom());
                                    cell_.setCellValue(lineBaseSmallType.getBaseLineValueFrom());
                                    cell_.setCellStyle(bodyContextCellStyle);


//                                    cell_.setCellValue(p.getPcbaLineNameCn());
//                                    cell_.setCellStyle(bodyContextCellStyle);
//                                    if(lineBaseSmallType.getPcbaProcess() != null && lineBaseSmallType.getPcbaProcess().getPcbaProcessNameCn() != null && !"".equals(lineBaseSmallType.getPcbaProcess().getPcbaProcessNameCn())){
//                                        if("SMT".equals(lineBaseSmallType.getPcbaProcess().getPcbaProcessNameCn().toUpperCase())){
//                                            //boolean b = false;
//                                            String n = "";
//                                            for (PcbaLine notSmtP : otherLineList) {
//                                                if("SMT".equals(lineBaseSmallType.getPcbaProcessSmt().getPcbaProcessNameCn())){
//                                                    n = p.getPcbaLineNameCn();
//                                                }else{
//                                                    if(notSmtP.getPcbaProcess().getPcbaProcessNameCn().contains(lineBaseSmallType.getPcbaProcessSmt().getPcbaProcessNameCn())){
//                                                        n = notSmtP.getPcbaLineNameCn();
//                                                        //b = true;
//                                                        break;
//                                                    }
//                                                }
//                                            }
//                                            if(!"".equals(n)){
//                                                cell_.setCellValue(n);
//                                                cell_.setCellStyle(bodyContextCellStyle);
//                                            }
//                                        }else{
//                                            String n = "";
//                                            for (PcbaLine notSmtP : otherLineList) {
//                                                if(notSmtP.getPcbaProcess().getPcbaProcessNameCn().contains(lineBaseSmallType.getPcbaProcess().getPcbaProcessNameCn())){
//                                                    n = notSmtP.getPcbaLineNameCn();
//                                                    break;
//                                                }
//                                            }
//                                            cell_.setCellValue(n);
//                                            cell_.setCellStyle(bodyContextCellStyle);
//                                        }
//                                    }

                                    // 项目小类
                                    cell_ = row_.createCell(2);
                                    cell_.setCellValue(lineBaseSmallType.getLineBaseSmallTypeName());
                                    cell_.setCellStyle(bodyContextCellStyle);

                                    // 整线能力评估项
                                    cell_ = row_.createCell(3);
                                    cell_.setCellValue(baseCapacityRule.getBaseCapacityRuleName());
                                    cell_.setCellStyle(bodyContextCellStyle);

                                    // 基线能力反馈
                                    cell_ = row_.createCell(4);
                                    cell_.setCellValue((baseCapacityRule.getLineBaseParamValue() != null && !"".equals(baseCapacityRule.getLineBaseParamValue())) ? baseCapacityRule.getLineBaseParamValue() : "");
                                    cell_.setCellStyle(bodyContextCellStyle);
                                }
                                if (lineBaseSmallType.getBaseCapacityRuleList().size() > 1) {
                                    if (index > beginIndex2) {
                                        sheet.addMergedRegion(new CellRangeAddress(beginIndex2, index, 2, 2));
                                        sheet.addMergedRegion(new CellRangeAddress(beginIndex2, index, 1, 1));
                                        beginIndex2 = index + 1;
                                    }
                                } else {
                                    beginIndex2 = index + 1;
                                }
                            }
                        }
                        //if(lineBaseBigType.getLineBaseSmallTypeList().size() > 1){
                        if (index > beginIndex1) {
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 0, 0));
                            beginIndex1 = index + 1;
                        }
                        /*}else{
                            beginIndex1 = index + 1;
                        }*/
                    }
                }
                /*if(index > 1){
                    sheet.addMergedRegion(new CellRangeAddress(1, index, 1, 1));
                }*/
            }
            String fileName = excelFileName + CommonUtils.getTimestamp() + ".xlsx";
            String pathPrefix = fileSaveUrl + "exportExcels\\";
            File folder = new File(pathPrefix);
            if (!folder.isDirectory()) {
                folder.mkdirs();
            }
            String filePath = pathPrefix + fileName;
            // 导出Excel文件
            FileOutputStream outputStream = new FileOutputStream(filePath);
            workbook.write(outputStream);
            workbook.close();
            outputStream.close();

            byte[] data = null;
            InputStream in = new FileInputStream(filePath);
            data = new byte[in.available()];
            in.read(data);
            in.close();
            java.util.Base64.Encoder encoder = java.util.Base64.getEncoder();
            String base64 = encoder.encodeToString(data);

            Map<String, Object> resMap = new HashMap<>();
            resMap.put("base64", base64);
            resMap.put("fileName", fileName);
            resMap.put("lineList", smtLineList);
            return ResultUtil.success(resMap);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result exportBaseCapacityExcelV3(String pcbaLineIds) {
        try {
            if (pcbaLineIds == null || "".equals(pcbaLineIds)) {
                return ResultUtil.error(500, "缺少参数pcbaLineIds", "Miss Param pcbaLineIds", null);
            }

            Integer pressfitProcessId = ProcessIdConfig.PressfitProcessId;
            Integer aoiPressfitProcessId = ProcessIdConfig.AoiPressfitProcessId;

            String[] arr = pcbaLineIds.split(",");

            List<PcbaLine> list = new ArrayList<>();
            for (String s : arr) {
                PcbaLine pcbaLine = pcbaLineDao.getPcbaLineById(Integer.parseInt(s));
                pcbaLine.setPcbaCompany(pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId()));
                pcbaLine.setPcbaWorkshop(pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId()));
                pcbaLine.setPcbaProcess(pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId()));
                Result result = coreAlgorithmService.calcLineBaseCapacity(Integer.parseInt(s));
                if (result.getCode() == 200) {
                    //System.out.println((Map<String,Object>)result.getData());
                    pcbaLine.setBaseCapacityMap((Map<String, Object>) result.getData());
                }
                list.add(pcbaLine);
            }

            // SMT线体
            List<PcbaLine> smtLineList = new ArrayList<>();
            // 非 SMT线体
            List<PcbaLine> otherLineList = new ArrayList<>();
            // pressfit 线体
            List<PcbaLine> pressfitLineList = new ArrayList<>();
            // aoi-pressfit 线体
            List<PcbaLine> aoiPressfitLineList = new ArrayList<>();

            // 每个smt线体中包含的设备
            //List<Map<String, Object>> smtContainsDeviceTypeIdList = new ArrayList<>();
            // 非smt线体中包含的设备
            //List<PcbaDevice> otherContainsDeviceTypeIdList = new ArrayList<>();
            for (PcbaLine pcbaLine : list) {
                if (pcbaLine.getPcbaLineType() == 1) {
                    smtLineList.add(pcbaLine);
                } else {
                    //if(pcbaLine.getPcbaLineNameCn() != null && (!(pcbaLine.getPcbaLineNameCn().toUpperCase()).contains("PTH"))){
                    otherLineList.add(pcbaLine);
                    //}
                }
                if (pcbaLine.getPcbaProcessId().equals(pressfitProcessId)) {
                    pressfitLineList.add(pcbaLine);
                }
                if (pcbaLine.getPcbaProcessId().equals(aoiPressfitProcessId)) {
                    aoiPressfitLineList.add(pcbaLine);
                }
            }

            List<LineBaseBigType> allLineBaseBigTypeList = lineBaseBigTypeDao.getAllLineBaseBigType(null);
            for (LineBaseBigType lineBaseBigType : allLineBaseBigTypeList) {
                List<LineBaseSmallType> allLineBaseSmallTypeList = lineBaseSmallTypeDao.getAllLineBaseSmallTypeByBigType(null, lineBaseBigType.getLineBaseBigTypeId());
                for (LineBaseSmallType lineBaseSmallType : allLineBaseSmallTypeList) {
                    lineBaseSmallType.setPcbaProcess(pcbaProcessDao.getPcbaProcessById(lineBaseSmallType.getPcbaProcessId()));
                    lineBaseSmallType.setPcbaProcessSmt(pcbaProcessDao.getPcbaProcessById(lineBaseSmallType.getPcbaProcessIdSmt()));
                    List<BaseCapacityRule> allBaseCapacityRule = baseCapacityRuleDao.getAllBaseCapacityRule(null, lineBaseBigType.getLineBaseBigTypeId(), lineBaseSmallType.getLineBaseSmallTypeId());
                    lineBaseSmallType.setBaseCapacityRuleList(allBaseCapacityRule);
                }
                lineBaseBigType.setLineBaseSmallTypeList(allLineBaseSmallTypeList);
            }

            // 将 非 SMT 的value 填充到 SMT 的空value
            // 若SMT线体中存在对应离线设备，则取SMT线体中此设备的值，否则取离线设备的值
            for (PcbaLine pcbaLine : smtLineList) {
                List<BaseCapacityRule> finalKeyAndValueList = (List<BaseCapacityRule>) pcbaLine.getBaseCapacityMap().get("finalKeyAndValueList");
                for (BaseCapacityRule baseCapacityRule : finalKeyAndValueList) {
                    baseCapacityRule.setBaseLineValueFrom(pcbaLine.getPcbaLineNameCn());
                    for (PcbaLine pcbaLine2 : otherLineList) {
                        Map<String, Object> baseCapacityMap2 = pcbaLine2.getBaseCapacityMap();
                        List<BaseCapacityRule> finalKeyAndValueList2 = (List<BaseCapacityRule>) baseCapacityMap2.get("finalKeyAndValueList");
                        for (BaseCapacityRule baseCapacityRule2 : finalKeyAndValueList2) {
                            if (baseCapacityRule2.getValueFromOnline() == 2) {
                                // SMT线体中有，则抓SMT的值，否则抓离线
                                if (baseCapacityRule.getLineBaseParamKey().equals(baseCapacityRule2.getLineBaseParamKey())) {
                                    if ((baseCapacityRule.getLineBaseParamValue() == null || "".equals(baseCapacityRule.getLineBaseParamValue())) && baseCapacityRule2.getLineBaseParamValue() != null && !"".equals(baseCapacityRule2.getLineBaseParamValue())) {
                                        baseCapacityRule.setLineBaseParamValue(baseCapacityRule2.getLineBaseParamValue());
                                        baseCapacityRule.setBaseLineValueFrom(pcbaLine2.getPcbaLineNameCn());
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            for (PcbaLine pcbaLine : smtLineList) {
                List<BaseCapacityRule> finalKeyAndValueList = (List<BaseCapacityRule>) pcbaLine.getBaseCapacityMap().get("finalKeyAndValueList");
                ;
                for (BaseCapacityRule baseCapacityRule : finalKeyAndValueList) {
                    if (baseCapacityRule != null && baseCapacityRule.getValueFromOnline() == 3) {
                        // 初始化将 这几个 设置为 NA
                        baseCapacityRule.setLineBaseParamValue("NA");
                        baseCapacityRule.setBaseLineValueFrom("NA");
                    }
                }
            }

            for (PcbaLine pcbaLine : smtLineList) {
                List<BaseCapacityRule> finalKeyAndValueList = (List<BaseCapacityRule>) pcbaLine.getBaseCapacityMap().get("finalKeyAndValueList");
                for (BaseCapacityRule baseCapacityRule : finalKeyAndValueList) {
                    if (aoiPressfitLineList.size() > 0) {
                        for (PcbaLine pcbaLine2 : aoiPressfitLineList) {
                            Map<String, Object> baseCapacityMap2 = pcbaLine2.getBaseCapacityMap();
                            List<BaseCapacityRule> finalKeyAndValueList2 = (List<BaseCapacityRule>) baseCapacityMap2.get("finalKeyAndValueList");
                            for (BaseCapacityRule baseCapacityRule2 : finalKeyAndValueList2) {
                                if (baseCapacityRule2.getValueFromOnline() == 3) {
                                    if (baseCapacityRule.getLineBaseParamKey().equals(baseCapacityRule2.getLineBaseParamKey())) {
                                        baseCapacityRule.setLineBaseParamValue(baseCapacityRule2.getLineBaseParamValue());
                                        baseCapacityRule.setBaseLineValueFrom(pcbaLine2.getPcbaLineNameCn());
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (pressfitLineList.size() > 0 && aoiPressfitLineList.size() == 0) {
                        for (PcbaLine pcbaLine2 : pressfitLineList) {
                            Map<String, Object> baseCapacityMap2 = pcbaLine2.getBaseCapacityMap();
                            List<BaseCapacityRule> finalKeyAndValueList2 = (List<BaseCapacityRule>) baseCapacityMap2.get("finalKeyAndValueList");
                            for (BaseCapacityRule baseCapacityRule2 : finalKeyAndValueList2) {
                                if (baseCapacityRule2.getValueFromOnline() == 3) {
                                    if (baseCapacityRule.getLineBaseParamKey().equals(baseCapacityRule2.getLineBaseParamKey())) {
                                        baseCapacityRule.setLineBaseParamValue(baseCapacityRule2.getLineBaseParamValue());
                                        baseCapacityRule.setBaseLineValueFrom(pcbaLine2.getPcbaLineNameCn());
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                for (BaseCapacityRule baseCapacityRule : finalKeyAndValueList) {
                    if (baseCapacityRule.getLineBaseParamValue() == null || "".equals(baseCapacityRule.getLineBaseParamValue())) {
                        baseCapacityRule.setLineBaseParamValue("NA");
                        baseCapacityRule.setBaseLineValueFrom("NA");
                    }
                }

                Map<String, Object> map = new HashMap<>();
                map.put("finalKeyAndValueList", finalKeyAndValueList);
                pcbaLine.setBaseCapacityMap(map);
            }

            // 创建工作簿对象
            Workbook workbook = new XSSFWorkbook();
            String excelFileName = "线体设备整线能力反馈表";
            for (PcbaLine p : smtLineList) {
                int index = 0;
                int beginIndex1 = 1;
                int beginIndex2 = 1;
                //String excelName = p.getPcbaLineNameCn() + "(" + p.getPcbaCompany().getPcbaCompanyNameCn() + "-" + p.getPcbaWorkshop().getPcbaWorkshopNameCn() + ")";
                // XX工厂线体设备整线能力反馈报告
                String excelName = p.getPcbaCompany().getPcbaCompanyNameCn() + "工厂线体设备整线能力反馈报告（" + p.getPcbaLineNameCn() + "）";
                // 创建工作表对象
                Sheet sheet = workbook.createSheet(CommonUtils.handleSheetName(excelName));

                Map<String, Object> m = p.getBaseCapacityMap();
                // System.out.println(allLineBaseBigTypeList);
                // 带有数据的项目大类
                //List<LineBaseBigType> lineBaseBigTypeList = (List<LineBaseBigType>)m.get("lineBaseBigTypeList");
                //带有数据的所有参数项
                List<BaseCapacityRule> baseCapacityRules = (List<BaseCapacityRule>) m.get("finalKeyAndValueList");

                for (LineBaseBigType lineBaseBigType : allLineBaseBigTypeList) {
                    for (LineBaseSmallType lineBaseSmallType : lineBaseBigType.getLineBaseSmallTypeList()) {
                        for (BaseCapacityRule baseCapacityRule : lineBaseSmallType.getBaseCapacityRuleList()) {
                            for (BaseCapacityRule capacityRule : baseCapacityRules) {
                                if (baseCapacityRule.getLineBaseParamKey().equals(capacityRule.getLineBaseParamKey())) {
                                    baseCapacityRule.setLineBaseParamValue(capacityRule.getLineBaseParamValue());
                                    baseCapacityRule.setBaseLineValueFrom(capacityRule.getBaseLineValueFrom());
                                    break;
                                }
                            }
                        }
                    }
                }
                for (LineBaseBigType lineBaseBigType : allLineBaseBigTypeList) {
                    if (lineBaseBigType.getLineBaseSmallTypeList() != null && lineBaseBigType.getLineBaseSmallTypeList().size() > 0) {
                        for (LineBaseSmallType lineBaseSmallType : lineBaseBigType.getLineBaseSmallTypeList()) {
                            List<String> valueFromList = new ArrayList<>();
                            if (lineBaseSmallType.getBaseCapacityRuleList() != null && lineBaseSmallType.getBaseCapacityRuleList().size() > 0) {
                                for (BaseCapacityRule baseCapacityRule : lineBaseSmallType.getBaseCapacityRuleList()) {
                                    // 过滤重复的  和  NA
                                    if (!valueFromList.contains(baseCapacityRule.getBaseLineValueFrom()) && !"NA".equals(baseCapacityRule.getBaseLineValueFrom())) {
                                        valueFromList.add(baseCapacityRule.getBaseLineValueFrom());
                                    }
                                }
                            }
                            //System.out.println(valueFromList);
                            // valueFromList 长度为0 则渲染NA
                            // 长度不为0， 有SMT则渲染SMT,否则渲染其他
                            if (valueFromList.size() == 0) {
                                lineBaseSmallType.setBaseLineValueFrom("NA");
                            } else {
                                if (valueFromList.toString().contains("SMT")) {
                                    for (String s : valueFromList) {
                                        if (s.toUpperCase().contains("SMT")) {
                                            lineBaseSmallType.setBaseLineValueFrom(s);
                                            break;
                                        }
                                    }
                                } else {
                                    lineBaseSmallType.setBaseLineValueFrom(valueFromList.get(0));
                                }
                            }
                        }
                    }
                }

                CellStyle bodyContextCellStyle = workbook.createCellStyle();
                DataFormat format = workbook.createDataFormat();
                bodyContextCellStyle.setDataFormat(format.getFormat("@"));
                bodyContextCellStyle.setBorderBottom(BorderStyle.THIN);
                bodyContextCellStyle.setBorderLeft(BorderStyle.THIN);
                bodyContextCellStyle.setBorderRight(BorderStyle.THIN);
                bodyContextCellStyle.setBorderTop(BorderStyle.THIN);
                bodyContextCellStyle.setAlignment(HorizontalAlignment.LEFT);
                bodyContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

                CellStyle titleContextCellStyle = workbook.createCellStyle();
                titleContextCellStyle.setBorderBottom(BorderStyle.THIN);
                titleContextCellStyle.setBorderLeft(BorderStyle.THIN);
                titleContextCellStyle.setBorderRight(BorderStyle.THIN);
                titleContextCellStyle.setBorderTop(BorderStyle.THIN);
                titleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
                titleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
                // 设置背景色为红色
                titleContextCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
                // 创建字体对象
                Font titleFont = workbook.createFont();
                // 设置字体颜色为蓝色
                titleFont.setColor(IndexedColors.WHITE.getIndex());
                titleFont.setBold(true);
                titleContextCellStyle.setFont(titleFont);
                // 设置填充类型为填充实体背景
                titleContextCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                Row row = sheet.createRow(0);
                Cell cell;

                List<Map<String, Object>> titleList = new ArrayList<>();
                Map<String, Object> map = new HashMap<>();
                map = new HashMap<>();
                map.put("title", "项目大类");
                map.put("width", 10000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "线体名称");
                map.put("width", 5000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "项目小类");
                map.put("width", 10000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "整线能力评估项");
                map.put("width", 15000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "基线能力反馈");
                map.put("width", 6000);
                titleList.add(map);
                row = sheet.createRow(0);
                for (int a = 0; a < titleList.size(); a++) {
                    sheet.setColumnWidth(a, Integer.parseInt(titleList.get(a).get("width").toString()));
                    // sheet.setDefaultRowHeight((short)450);
                    cell = row.createCell(a);
                    // 向单元格中写入数据
                    cell.setCellValue(titleList.get(a).get("title").toString());
                    cell.setCellStyle(titleContextCellStyle);
                }

                for (LineBaseBigType lineBaseBigType : allLineBaseBigTypeList) {
                    if (lineBaseBigType.getLineBaseSmallTypeList() != null && lineBaseBigType.getLineBaseSmallTypeList().size() > 0) {
                        for (LineBaseSmallType lineBaseSmallType : lineBaseBigType.getLineBaseSmallTypeList()) {
                            if (lineBaseSmallType.getBaseCapacityRuleList() != null && lineBaseSmallType.getBaseCapacityRuleList().size() > 0) {
                                for (BaseCapacityRule baseCapacityRule : lineBaseSmallType.getBaseCapacityRuleList()) {
                                    index++;
                                    Row row_ = sheet.createRow(index);

                                    // 项目大类
                                    Cell cell_ = row_.createCell(0);
                                    cell_.setCellValue(lineBaseBigType.getLineBaseBigTypeName());
                                    cell_.setCellStyle(bodyContextCellStyle);

                                    // 线体名称
                                    cell_ = row_.createCell(1);
                                    // cell_.setCellValue(baseCapacityRule.getBaseLineValueFrom());
                                    cell_.setCellValue(lineBaseSmallType.getBaseLineValueFrom());
                                    cell_.setCellStyle(bodyContextCellStyle);


//                                    cell_.setCellValue(p.getPcbaLineNameCn());
//                                    cell_.setCellStyle(bodyContextCellStyle);
//                                    if(lineBaseSmallType.getPcbaProcess() != null && lineBaseSmallType.getPcbaProcess().getPcbaProcessNameCn() != null && !"".equals(lineBaseSmallType.getPcbaProcess().getPcbaProcessNameCn())){
//                                        if("SMT".equals(lineBaseSmallType.getPcbaProcess().getPcbaProcessNameCn().toUpperCase())){
//                                            //boolean b = false;
//                                            String n = "";
//                                            for (PcbaLine notSmtP : otherLineList) {
//                                                if("SMT".equals(lineBaseSmallType.getPcbaProcessSmt().getPcbaProcessNameCn())){
//                                                    n = p.getPcbaLineNameCn();
//                                                }else{
//                                                    if(notSmtP.getPcbaProcess().getPcbaProcessNameCn().contains(lineBaseSmallType.getPcbaProcessSmt().getPcbaProcessNameCn())){
//                                                        n = notSmtP.getPcbaLineNameCn();
//                                                        //b = true;
//                                                        break;
//                                                    }
//                                                }
//                                            }
//                                            if(!"".equals(n)){
//                                                cell_.setCellValue(n);
//                                                cell_.setCellStyle(bodyContextCellStyle);
//                                            }
//                                        }else{
//                                            String n = "";
//                                            for (PcbaLine notSmtP : otherLineList) {
//                                                if(notSmtP.getPcbaProcess().getPcbaProcessNameCn().contains(lineBaseSmallType.getPcbaProcess().getPcbaProcessNameCn())){
//                                                    n = notSmtP.getPcbaLineNameCn();
//                                                    break;
//                                                }
//                                            }
//                                            cell_.setCellValue(n);
//                                            cell_.setCellStyle(bodyContextCellStyle);
//                                        }
//                                    }

                                    // 项目小类
                                    cell_ = row_.createCell(2);
                                    cell_.setCellValue(lineBaseSmallType.getLineBaseSmallTypeName());
                                    cell_.setCellStyle(bodyContextCellStyle);

                                    // 整线能力评估项
                                    cell_ = row_.createCell(3);
                                    cell_.setCellValue(baseCapacityRule.getBaseCapacityRuleName());
                                    cell_.setCellStyle(bodyContextCellStyle);

                                    // 基线能力反馈
                                    cell_ = row_.createCell(4);
                                    cell_.setCellValue((baseCapacityRule.getLineBaseParamValue() != null && !"".equals(baseCapacityRule.getLineBaseParamValue())) ? baseCapacityRule.getLineBaseParamValue() : "");
                                    cell_.setCellStyle(bodyContextCellStyle);
                                }
                                if (lineBaseSmallType.getBaseCapacityRuleList().size() > 1) {
                                    if (index > beginIndex2) {
                                        sheet.addMergedRegion(new CellRangeAddress(beginIndex2, index, 2, 2));
                                        sheet.addMergedRegion(new CellRangeAddress(beginIndex2, index, 1, 1));
                                        beginIndex2 = index + 1;
                                    }
                                } else {
                                    beginIndex2 = index + 1;
                                }
                            }
                        }
                        //if(lineBaseBigType.getLineBaseSmallTypeList().size() > 1){
                        if (index > beginIndex1) {
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 0, 0));
                            beginIndex1 = index + 1;
                        }
                        /*}else{
                            beginIndex1 = index + 1;
                        }*/
                    }
                }
                /*if(index > 1){
                    sheet.addMergedRegion(new CellRangeAddress(1, index, 1, 1));
                }*/
            }
            String fileName = excelFileName + CommonUtils.getTimestamp() + ".xlsx";
            String pathPrefix = fileSaveUrl + "exportExcels\\";
            File folder = new File(pathPrefix);
            if (!folder.isDirectory()) {
                folder.mkdirs();
            }
            String filePath = pathPrefix + fileName;
            // 导出Excel文件
            FileOutputStream outputStream = new FileOutputStream(filePath);
            workbook.write(outputStream);
            workbook.close();
            outputStream.close();

            byte[] data = null;
            InputStream in = new FileInputStream(filePath);
            data = new byte[in.available()];
            in.read(data);
            in.close();
            java.util.Base64.Encoder encoder = java.util.Base64.getEncoder();
            String base64 = encoder.encodeToString(data);

            Map<String, Object> resMap = new HashMap<>();
            resMap.put("base64", base64);
            resMap.put("fileName", fileName);
            resMap.put("lineList", smtLineList);
            return ResultUtil.success(resMap);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result exportTechCapacityExcel(String pcbaLineIds) {
        try {
            if (pcbaLineIds == null || "".equals(pcbaLineIds)) {
                return ResultUtil.error(500, "缺少参数pcbaLineIds", "Miss Param pcbaLineIds", null);
            }
            String[] arr = pcbaLineIds.split(",");
            List<PcbaLine> list = new ArrayList<>();
            for (String s : arr) {
                PcbaLine pcbaLine = pcbaLineDao.getPcbaLineById(Integer.parseInt(s));
                pcbaLine.setPcbaCompany(pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId()));
                pcbaLine.setPcbaWorkshop(pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId()));
                Result result = lineTechCapacityValueService.getAllLineTechCapacityValueByLineId(Integer.parseInt(s));
                if (result.getCode() == 200) {
                    pcbaLine.setTechCapacity((LineTechBigType) result.getData());
                    list.add(pcbaLine);
                }
            }
            // 创建工作簿对象
            Workbook workbook = new XSSFWorkbook();
            String excelFileName = "线体工艺能力参数反馈表";
            for (PcbaLine p : list) {
                int index = 0;
                int beginIndex1 = 1;
                int beginIndex2 = 1;
                String excelName = p.getPcbaLineNameCn() + "(" + p.getPcbaCompany().getPcbaCompanyNameCn() + "-" + p.getPcbaWorkshop().getPcbaWorkshopNameCn() + ")";
                // 创建工作表对象
                Sheet sheet = workbook.createSheet(CommonUtils.handleSheetName(excelName));

                LineTechBigType lineTechBigType = p.getTechCapacity();

                CellStyle bodyContextCellStyle = workbook.createCellStyle();
                DataFormat format = workbook.createDataFormat();
                bodyContextCellStyle.setDataFormat(format.getFormat("@"));
                bodyContextCellStyle.setBorderBottom(BorderStyle.THIN);
                bodyContextCellStyle.setBorderLeft(BorderStyle.THIN);
                bodyContextCellStyle.setBorderRight(BorderStyle.THIN);
                bodyContextCellStyle.setBorderTop(BorderStyle.THIN);
                bodyContextCellStyle.setAlignment(HorizontalAlignment.LEFT);
                bodyContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

                CellStyle titleContextCellStyle = workbook.createCellStyle();
                titleContextCellStyle.setBorderBottom(BorderStyle.THIN);
                titleContextCellStyle.setBorderLeft(BorderStyle.THIN);
                titleContextCellStyle.setBorderRight(BorderStyle.THIN);
                titleContextCellStyle.setBorderTop(BorderStyle.THIN);
                titleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
                titleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
                // 设置背景色为红色
                titleContextCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
                // 创建字体对象
                Font titleFont = workbook.createFont();
                // 设置字体颜色为蓝色
                titleFont.setColor(IndexedColors.WHITE.getIndex());
                titleFont.setBold(true);
                titleContextCellStyle.setFont(titleFont);
                // 设置填充类型为填充实体背景
                titleContextCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                Row row = sheet.createRow(0);
                Cell cell;

                List<Map<String, Object>> titleList = new ArrayList<>();
                Map<String, Object> map = new HashMap<>();
                map = new HashMap<>();
                map.put("title", "线体名称");
                map.put("width", 3000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "线体类型");
                map.put("width", 10000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "能力项");
                map.put("width", 15000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "宣称能力");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "实际能力");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "认证开始时间");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "认证结束时间");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "认证状态");
                map.put("width", 6000);
                titleList.add(map);
                row = sheet.createRow(0);
                for (int a = 0; a < titleList.size(); a++) {
                    sheet.setColumnWidth(a, Integer.parseInt(titleList.get(a).get("width").toString()));
                    // sheet.setDefaultRowHeight((short)450);
                    cell = row.createCell(a);
                    // 向单元格中写入数据
                    cell.setCellValue(titleList.get(a).get("title").toString());
                    cell.setCellStyle(titleContextCellStyle);
                }

                if (lineTechBigType != null && lineTechBigType.getLineTechSmallTypeList() != null && lineTechBigType.getLineTechSmallTypeList().size() > 0) {
                    for (LineTechSmallType lineTechSmallType : lineTechBigType.getLineTechSmallTypeList()) {
                        if (lineTechSmallType.getTechCapacityRuleList() != null && lineTechSmallType.getTechCapacityRuleList().size() > 0) {
                            for (TechCapacityRule techCapacityRule : lineTechSmallType.getTechCapacityRuleList()) {
                                index++;
                                Row row_ = sheet.createRow(index);

                                // 线体名称
                                Cell cell_ = row_.createCell(0);
                                cell_.setCellValue(lineTechBigType.getLineTechBigTypeName() + "(" + p.getPcbaLineNameCn() + ")");
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 线体类型
                                cell_ = row_.createCell(1);
                                cell_.setCellValue(lineTechSmallType.getLineTechSmallTypeName());
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 能力项
                                cell_ = row_.createCell(2);
                                cell_.setCellValue(techCapacityRule.getTechCapacityRuleName());
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 宣称能力
                                cell_ = row_.createCell(3);
                                cell_.setCellValue(techCapacityRule.getDeclareValue());
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 实际能力
                                cell_ = row_.createCell(4);
                                cell_.setCellValue(techCapacityRule.getActualValue());
                                cell_.setCellStyle(bodyContextCellStyle);

                                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                                // 认证开始时间
                                cell_ = row_.createCell(5);
                                String beginDateStr = "";
                                if (p.getBeginTimeActual() != null) {
                                    beginDateStr = dateFormat.format(p.getBeginTimeActual());
                                }
                                cell_.setCellValue(beginDateStr);
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 认证结束时间
                                cell_ = row_.createCell(6);
                                String endDateStr = "";
                                if (p.getEndTimeActual() != null) {
                                    endDateStr = dateFormat.format(p.getEndTimeActual());
                                }
                                cell_.setCellValue(endDateStr);
                                cell_.setCellStyle(bodyContextCellStyle);

                                // 认证状态
                                // 1：认证通过  2：认证未通过  3：认证中   4：待提交认证
                                cell_ = row_.createCell(7);
                                cell_.setCellValue(p.getParamsStatusActual() != null ? (p.getParamsStatusActual() == 1 ? "认证通过" : (p.getParamsStatusActual() == 2 ? "认证未通过" : (p.getParamsStatusActual() == 3 ? "认证中" : (p.getParamsStatusActual() == 4 ? "待提交认证" : (p.getParamsStatusActual() == 5 ? "超出有效期" : ""))))) : "");
                                cell_.setCellStyle(bodyContextCellStyle);
                            }
                            if (lineTechSmallType.getTechCapacityRuleList().size() > 1) {
                                if (index > beginIndex2) {
                                    sheet.addMergedRegion(new CellRangeAddress(beginIndex2, index, 1, 1));
                                    beginIndex2 = index + 1;
                                }
                            } else {
                                beginIndex2 = index + 1;
                            }
                        }
                    }
                    if (index > beginIndex1) {
                        sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 0, 0));
                        sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 5, 5));
                        sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 6, 6));
                        sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 7, 7));
                        beginIndex1 = index + 1;
                    }
                }
            }
            String fileName = excelFileName + CommonUtils.getTimestamp() + ".xlsx";
            String pathPrefix = fileSaveUrl + "exportExcels\\";
            File folder = new File(pathPrefix);
            if (!folder.isDirectory()) {
                folder.mkdirs();
            }
            String filePath = pathPrefix + fileName;
            // 导出Excel文件
            FileOutputStream outputStream = new FileOutputStream(filePath);
            workbook.write(outputStream);
            workbook.close();
            outputStream.close();

            byte[] data = null;
            InputStream in = new FileInputStream(filePath);
            data = new byte[in.available()];
            in.read(data);
            in.close();
            java.util.Base64.Encoder encoder = java.util.Base64.getEncoder();
            String base64 = encoder.encodeToString(data);

            Map<String, Object> resMap = new HashMap<>();
            resMap.put("base64", base64);
            resMap.put("fileName", fileName);
            return ResultUtil.success(resMap);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result exportLineExcel(String searchPcbaLineName, Integer pcbaCompanyId, Integer pcbaWorkshopId, Integer pcbaProcessId) {
        try {
            List<PcbaLine> list = pcbaLineDao.getAllPcbaLine(searchPcbaLineName, pcbaCompanyId, pcbaWorkshopId, pcbaProcessId, null, null, null, null, null, null, null);
            for (PcbaLine pcbaLine : list) {
                pcbaLine.setPcbaCompany(pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId()));
                pcbaLine.setPcbaWorkshop(pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId()));
                pcbaLine.setPcbaProcess(pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId()));

                List<PcbaDevice> pcbaDeviceByLine = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                for (PcbaDevice pcbaDevice : pcbaDeviceByLine) {
                    pcbaDevice.setPcbaDeviceType(pcbaDeviceTypeDao.getById(pcbaDevice.getPcbaDeviceTypeId()));

                    PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                    pcbaDeviceResource.setBrand(brandDao.getBrandById(pcbaDeviceResource.getBrandId()));
                    pcbaDeviceResource.setBrandType(brandTypeDao.getBrandTypeById(pcbaDeviceResource.getBrandTypeId()));

                    pcbaDevice.setPcbaDeviceResource(pcbaDeviceResource);
                }

                pcbaLine.setPcbaDeviceList(pcbaDeviceByLine);
            }
            // 创建工作簿对象
            Workbook workbook = new XSSFWorkbook();
            String excelFileName = "线体清单列表";
            for (PcbaLine p : list) {
                int index = 0;
                String excelName = p.getPcbaLineNameCn() + "(" + p.getPcbaCompany().getPcbaCompanyNameCn() + "-" + p.getPcbaWorkshop().getPcbaWorkshopNameCn() + ")";
                // 创建工作表对象
                Sheet sheet = workbook.createSheet(CommonUtils.handleSheetName(excelName));

                LineTechBigType lineTechBigType = p.getTechCapacity();

                CellStyle bodyContextCellStyle = workbook.createCellStyle();
                DataFormat format = workbook.createDataFormat();
                bodyContextCellStyle.setDataFormat(format.getFormat("@"));
                bodyContextCellStyle.setBorderBottom(BorderStyle.THIN);
                bodyContextCellStyle.setBorderLeft(BorderStyle.THIN);
                bodyContextCellStyle.setBorderRight(BorderStyle.THIN);
                bodyContextCellStyle.setBorderTop(BorderStyle.THIN);
                bodyContextCellStyle.setAlignment(HorizontalAlignment.LEFT);
                bodyContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

                CellStyle titleContextCellStyle = workbook.createCellStyle();
                titleContextCellStyle.setBorderBottom(BorderStyle.THIN);
                titleContextCellStyle.setBorderLeft(BorderStyle.THIN);
                titleContextCellStyle.setBorderRight(BorderStyle.THIN);
                titleContextCellStyle.setBorderTop(BorderStyle.THIN);
                titleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
                titleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
                // 设置背景色为红色
                titleContextCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
                // 创建字体对象
                Font titleFont = workbook.createFont();
                // 设置字体颜色为蓝色
                titleFont.setColor(IndexedColors.WHITE.getIndex());
                titleFont.setBold(true);
                titleContextCellStyle.setFont(titleFont);
                // 设置填充类型为填充实体背景
                titleContextCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                Row row = sheet.createRow(0);
                Cell cell;

                cell = row.createCell(0);
                cell.setCellValue("线体信息");
                cell.setCellStyle(titleContextCellStyle);

                cell = row.createCell(6);
                cell.setCellValue("设备信息");
                cell.setCellStyle(titleContextCellStyle);

                // 合并 0-5 列   6-12列
                sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));
                sheet.addMergedRegion(new CellRangeAddress(0, 0, 6, 12));

                List<Map<String, Object>> titleList = new ArrayList<>();
                Map<String, Object> map = new HashMap<>();
                map = new HashMap<>();
                map.put("title", "线体名称");
                map.put("width", 3000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "线体类型");
                map.put("width", 10000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "工厂");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "车间");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "工序");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "外协厂实际车间名称");
                map.put("width", 15000);
                titleList.add(map);

                map = new HashMap<>();
                map.put("title", "序号");
                map.put("width", 4000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "设备类型");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "品牌");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "型号");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "资产编号");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "年限");
                map.put("width", 6000);
                titleList.add(map);
                map = new HashMap<>();
                map.put("title", "用途");
                map.put("width", 10000);
                titleList.add(map);

                row = sheet.createRow(1);
                for (int a = 0; a < titleList.size(); a++) {
                    sheet.setColumnWidth(a, Integer.parseInt(titleList.get(a).get("width").toString()));
                    // sheet.setDefaultRowHeight((short)450);
                    cell = row.createCell(a);
                    // 向单元格中写入数据
                    cell.setCellValue(titleList.get(a).get("title").toString());
                    cell.setCellStyle(titleContextCellStyle);
                }

                int i = 0;
                for (PcbaDevice pcbaDevice : p.getPcbaDeviceList()) {

                    LineLevel lineLevelById = lineLevelDao.getLineLevelById(p.getPcbaLineLevel());

                    i++;
                    row = sheet.createRow(2 + index);
                    cell = row.createCell(0);
                    cell.setCellValue(p.getPcbaLineNameCn());
                    cell = row.createCell(1);
                    cell.setCellValue(lineLevelById != null ? lineLevelById.getLineLevelName() : "");
                    cell = row.createCell(2);
                    cell.setCellValue(p.getPcbaCompany().getPcbaCompanyNameCn());
                    cell = row.createCell(3);
                    cell.setCellValue(p.getPcbaWorkshop().getPcbaWorkshopNameCn());
                    cell = row.createCell(4);
                    cell.setCellValue(p.getPcbaProcess().getPcbaProcessNameCn());
                    cell = row.createCell(5);
                    cell.setCellValue(p.getNotes());
                    cell = row.createCell(6);
                    cell.setCellValue(i);
                    cell = row.createCell(7);
                    cell.setCellValue(pcbaDevice.getPcbaDeviceType().getPcbaDeviceTypeNameCn());
                    cell = row.createCell(8);
                    cell.setCellValue(pcbaDevice.getPcbaDeviceResource().getBrand().getBrandName());
                    cell = row.createCell(9);
                    cell.setCellValue(pcbaDevice.getPcbaDeviceResource().getBrandType().getBrandTypeName());
                    cell = row.createCell(10);
                    cell.setCellValue(pcbaDevice.getAssetNumber());
                    if (pcbaDevice.getProductTime() != null && !"".equals(pcbaDevice.getProductTime().toString())) {
                        Date d1 = new Date();
                        LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        LocalDate ld2 = pcbaDevice.getProductTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        double age = CommonUtils.calculateYearDifference(ld2, ld1);
                        cell = row.createCell(11);
                        cell.setCellValue(age + "年");
                    }
                    cell = row.createCell(12);
                    cell.setCellValue(pcbaDevice.getPurpose());
                    index++;
                }

                if (index >= 2) {
                    sheet.addMergedRegion(new CellRangeAddress(2, index + 1, 0, 0));
                    sheet.addMergedRegion(new CellRangeAddress(2, index + 1, 1, 1));
                    sheet.addMergedRegion(new CellRangeAddress(2, index + 1, 2, 2));
                    sheet.addMergedRegion(new CellRangeAddress(2, index + 1, 3, 3));
                    sheet.addMergedRegion(new CellRangeAddress(2, index + 1, 4, 4));
                    sheet.addMergedRegion(new CellRangeAddress(2, index + 1, 5, 5));
                }
            }

            String fileName = excelFileName + CommonUtils.getTimestamp() + ".xlsx";
            String pathPrefix = fileSaveUrl + "exportExcels\\";
            File folder = new File(pathPrefix);
            if (!folder.isDirectory()) {
                folder.mkdirs();
            }
            String filePath = pathPrefix + fileName;
            // 导出Excel文件
            FileOutputStream outputStream = new FileOutputStream(filePath);
            workbook.write(outputStream);
            workbook.close();
            outputStream.close();

            byte[] data = null;
            InputStream in = new FileInputStream(filePath);
            data = new byte[in.available()];
            in.read(data);
            in.close();
            java.util.Base64.Encoder encoder = java.util.Base64.getEncoder();
            String base64 = encoder.encodeToString(data);

            Map<String, Object> resMap = new HashMap<>();
            resMap.put("base64", base64);
            resMap.put("fileName", fileName);
            return ResultUtil.success(resMap);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result exportLineExcelByType(Integer type, String pcbaLineIds) {
        try {
            if (type == null || "".equals(type.toString())) {
                return ResultUtil.error(500, "缺少参数type", "Miss Param type", null);
            }
            List<PcbaLine> pcbaLineList = new ArrayList<>();

            List<Integer> companyIdList = strToCompanys.getPcbaCompanyIdListFromStr();

            if (type == 1) {
                if (pcbaLineIds == null || "".equals(pcbaLineIds)) {
                    return ResultUtil.error(500, "缺少参数pcbaLineIds", "Miss Param pcbaLineIds", null);
                }
                List<Integer> pcbaLineIdList = new ArrayList<>();
                String[] split = pcbaLineIds.split(",");
                for (String s : split) {
                    pcbaLineIdList.add(Integer.parseInt(s));
                }
                pcbaLineList = pcbaLineDao.getPcbaLineByIds(pcbaLineIdList, type, companyIdList);
            } else {
                pcbaLineList = pcbaLineDao.getPcbaLineByIds(null, type, companyIdList);
            }

            for (PcbaLine pcbaLine : pcbaLineList) {
                pcbaLine.setPcbaCompany(pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId()));
                pcbaLine.setPcbaWorkshop(pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId()));
                pcbaLine.setPcbaProcess(pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId()));

                List<PcbaDevice> pcbaDeviceByLine = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                for (PcbaDevice pcbaDevice : pcbaDeviceByLine) {
                    pcbaDevice.setPcbaDeviceType(pcbaDeviceTypeDao.getById(pcbaDevice.getPcbaDeviceTypeId()));

                    PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                    pcbaDeviceResource.setBrand(brandDao.getBrandById(pcbaDeviceResource.getBrandId()));
                    pcbaDeviceResource.setBrandType(brandTypeDao.getBrandTypeById(pcbaDeviceResource.getBrandTypeId()));

                    pcbaDevice.setPcbaDeviceResource(pcbaDeviceResource);
                }

                pcbaLine.setPcbaDeviceList(pcbaDeviceByLine);
            }
            // 创建工作簿对象
            Workbook workbook = new XSSFWorkbook();
            String excelFileName = "线体清单";

            String excelName = excelFileName;
            // 创建工作表对象
            Sheet sheet = workbook.createSheet(CommonUtils.handleSheetName(excelName));

            CellStyle bodyContextCellStyle = workbook.createCellStyle();
            DataFormat format = workbook.createDataFormat();
            bodyContextCellStyle.setDataFormat(format.getFormat("@"));
            bodyContextCellStyle.setBorderBottom(BorderStyle.THIN);
            bodyContextCellStyle.setBorderLeft(BorderStyle.THIN);
            bodyContextCellStyle.setBorderRight(BorderStyle.THIN);
            bodyContextCellStyle.setBorderTop(BorderStyle.THIN);
            bodyContextCellStyle.setAlignment(HorizontalAlignment.LEFT);
            bodyContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

            CellStyle titleContextCellStyle = workbook.createCellStyle();
            titleContextCellStyle.setBorderBottom(BorderStyle.THIN);
            titleContextCellStyle.setBorderLeft(BorderStyle.THIN);
            titleContextCellStyle.setBorderRight(BorderStyle.THIN);
            titleContextCellStyle.setBorderTop(BorderStyle.THIN);
            titleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
            titleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            // 设置背景色为红色
            titleContextCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
            // 创建字体对象
            Font titleFont = workbook.createFont();
            // 设置字体颜色为蓝色
            titleFont.setColor(IndexedColors.WHITE.getIndex());
            titleFont.setBold(true);
            titleContextCellStyle.setFont(titleFont);
            // 设置填充类型为填充实体背景
            titleContextCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
            Row row = sheet.createRow(0);
            Cell cell;

            cell = row.createCell(0);
            cell.setCellValue("线体信息");
            cell.setCellStyle(titleContextCellStyle);

            cell = row.createCell(6);
            cell.setCellValue("设备信息");
            cell.setCellStyle(titleContextCellStyle);

            List<Map<String, Object>> titleList = new ArrayList<>();
            Map<String, Object> map = new HashMap<>();
            map = new HashMap<>();
            map.put("title", "线体名称");
            map.put("width", 3000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "线体类型");
            map.put("width", 6000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "工厂");
            map.put("width", 6000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "车间");
            map.put("width", 6000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "工序");
            map.put("width", 6000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "外协厂实际车间名称");
            map.put("width", 15000);
            titleList.add(map);

            map = new HashMap<>();
            map.put("title", "序号");
            map.put("width", 4000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "设备类型");
            map.put("width", 6000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "品牌");
            map.put("width", 6000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "型号");
            map.put("width", 6000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "资产编号");
            map.put("width", 6000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "年限");
            map.put("width", 6000);
            titleList.add(map);
            map = new HashMap<>();
            map.put("title", "用途");
            map.put("width", 10000);
            titleList.add(map);

            row = sheet.createRow(1);
            for (int a = 0; a < titleList.size(); a++) {
                sheet.setColumnWidth(a, Integer.parseInt(titleList.get(a).get("width").toString()));
                // sheet.setDefaultRowHeight((short)450);
                cell = row.createCell(a);
                // 向单元格中写入数据
                cell.setCellValue(titleList.get(a).get("title").toString());
                cell.setCellStyle(titleContextCellStyle);
            }

            // 合并 0-5 列   6-12列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 6, 12));

            int index = 0;
            int mIndex = 2;
            for (PcbaLine p : pcbaLineList) {
                LineTechBigType lineTechBigType = p.getTechCapacity();

                LineLevel lineLevelById = lineLevelDao.getLineLevelById(p.getPcbaLineLevel());


                int i = 0;
                for (PcbaDevice pcbaDevice : p.getPcbaDeviceList()) {
                    i++;
                    row = sheet.createRow(2 + index);
                    cell = row.createCell(0);
                    cell.setCellValue(p.getPcbaLineNameCn());
                    cell = row.createCell(1);
                    cell.setCellValue(lineLevelById != null ? lineLevelById.getLineLevelName() : "");
                    cell = row.createCell(2);
                    cell.setCellValue(p.getPcbaCompany().getPcbaCompanyNameCn());
                    cell = row.createCell(3);
                    cell.setCellValue(p.getPcbaWorkshop().getPcbaWorkshopNameCn());
                    cell = row.createCell(4);
                    cell.setCellValue(p.getPcbaProcess().getPcbaProcessNameCn());
                    cell = row.createCell(5);
                    cell.setCellValue(p.getNotes());
                    cell = row.createCell(6);
                    cell.setCellValue(i);
                    cell = row.createCell(7);
                    cell.setCellValue(pcbaDevice.getPcbaDeviceType().getPcbaDeviceTypeNameCn());
                    cell = row.createCell(8);
                    cell.setCellValue(pcbaDevice.getPcbaDeviceResource().getBrand().getBrandName());
                    cell = row.createCell(9);
                    cell.setCellValue(pcbaDevice.getPcbaDeviceResource().getBrandType().getBrandTypeName());
                    cell = row.createCell(10);
                    cell.setCellValue(pcbaDevice.getAssetNumber());
                    if (pcbaDevice.getProductTime() != null && !"".equals(pcbaDevice.getProductTime().toString())) {
                        Date d1 = new Date();
                        LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        LocalDate ld2 = pcbaDevice.getProductTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        double age = CommonUtils.calculateYearDifference(ld2, ld1);
                        cell = row.createCell(11);
                        cell.setCellValue(age + "年");
                    }
                    cell = row.createCell(12);
                    cell.setCellValue(pcbaDevice.getPurpose());
                    index++;
                }
                if (i >= 2) {
                    //System.out.println("i=" + i);
                    //System.out.println("合并:" + mIndex + "~" + (index + 1));
                    sheet.addMergedRegion(new CellRangeAddress(mIndex, index + 1, 0, 0));
                    sheet.addMergedRegion(new CellRangeAddress(mIndex, index + 1, 1, 1));
                    sheet.addMergedRegion(new CellRangeAddress(mIndex, index + 1, 2, 2));
                    sheet.addMergedRegion(new CellRangeAddress(mIndex, index + 1, 3, 3));
                    sheet.addMergedRegion(new CellRangeAddress(mIndex, index + 1, 4, 4));
                    sheet.addMergedRegion(new CellRangeAddress(mIndex, index + 1, 5, 5));
                }

                // 合并单元格并应用样式
//                RegionUtil.setBorderTop(BorderStyle.THIN, new CellRangeAddress(mIndex, index + 1, 0, 12), sheet);
//                RegionUtil.setBorderBottom(BorderStyle.THIN, new CellRangeAddress(mIndex, index + 1, 0, 12), sheet);
//                RegionUtil.setBorderLeft(BorderStyle.THIN, new CellRangeAddress(mIndex, index + 1, 0, 12), sheet);
//                RegionUtil.setBorderRight(BorderStyle.THIN, new CellRangeAddress(mIndex, index + 1, 0, 12), sheet);

                mIndex = index + 2;

            }
            String fileName = excelFileName + CommonUtils.getTimestamp() + ".xlsx";
            String pathPrefix = fileSaveUrl + "exportExcels\\";
            File folder = new File(pathPrefix);
            if (!folder.isDirectory()) {
                folder.mkdirs();
            }
            String filePath = pathPrefix + fileName;
            // 导出Excel文件
            FileOutputStream outputStream = new FileOutputStream(filePath);
            workbook.write(outputStream);
            workbook.close();
            outputStream.close();

            byte[] data = null;
            InputStream in = new FileInputStream(filePath);
            data = new byte[in.available()];
            in.read(data);
            in.close();
            java.util.Base64.Encoder encoder = java.util.Base64.getEncoder();
            String base64 = encoder.encodeToString(data);

            Map<String, Object> resMap = new HashMap<>();
            resMap.put("base64", base64);
            resMap.put("fileName", fileName);
            resMap.put("pcbaLineList", pcbaLineList);
            return ResultUtil.success(resMap);

        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result auditPcbaLineTechDeclare(String paramsNotesDeclare, Integer pcbaLineId, Integer paramsStatusDeclare) {
        try {
            if (paramsStatusDeclare == null || "".equals(paramsStatusDeclare.toString())) {
                return ResultUtil.error(500, "缺少参数paramsStatusDeclare", "Miss Param paramsStatusDeclare", null);
            }
            if (pcbaLineId == null || "".equals(pcbaLineId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaLineId", "Miss Param pcbaLineId", null);
            }
            String userId = UserHeaderHolder.getUserId();
            PcbaLine oldPcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);
            Date d = new Date();
            Integer integer = pcbaLineDao.auditPcbaLineTechDeclare(paramsNotesDeclare, pcbaLineId, paramsStatusDeclare, d);
            if (integer > 0) {

                PcbaLine newPcbaLine = new PcbaLine();
                newPcbaLine.setPcbaLineId(pcbaLineId);
                newPcbaLine.setParamsStatusDeclare(paramsStatusDeclare);
                newPcbaLine.setUpdateTime(d);
                newPcbaLine.setParamsNotesDeclare(paramsNotesDeclare);
                // 添加操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 1, d, JSONObject.toJSONString(oldPcbaLine), JSONObject.toJSONString(newPcbaLine)));

                return ResultUtil.success(null);
            }
            return ResultUtil.error(500, "操作失败", "Operate Fail", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result auditPcbaLineTechActual(String paramsNotesActual, Integer pcbaLineId, Integer paramsStatusActual) {
        try {
            if (paramsStatusActual == null || "".equals(paramsStatusActual.toString())) {
                return ResultUtil.error(500, "缺少参数paramsStatusActual", "Miss Param paramsStatusActual", null);
            }
            if (pcbaLineId == null || "".equals(pcbaLineId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaLineId", "Miss Param pcbaLineId", null);
            }
            String userId = UserHeaderHolder.getUserId();
            PcbaLine oldPcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);
            Date d = new Date();
            Integer integer = pcbaLineDao.auditPcbaLineTechActual(paramsNotesActual, pcbaLineId, paramsStatusActual, d);
            if (integer > 0) {

                PcbaLine newPcbaLine = new PcbaLine();
                newPcbaLine.setPcbaLineId(pcbaLineId);
                newPcbaLine.setParamsStatusActual(paramsStatusActual);
                newPcbaLine.setUpdateTime(d);
                newPcbaLine.setParamsNotesActual(paramsNotesActual);
                // 添加操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 1, d, JSONObject.toJSONString(oldPcbaLine), JSONObject.toJSONString(newPcbaLine)));

                /*// 添加 审核记录
                AuditHistory addAuditHistory = new AuditHistory();
                addAuditHistory.setAuditType(3);
                addAuditHistory.setCreateTime(d);
                addAuditHistory.setSubmitUserId(null);
                addAuditHistory.setAuditUserId(Integer.parseInt(userId));
                addAuditHistory.setAuditStatus(paramsStatusActual);
                addAuditHistory.setAuditNotes(paramsNotesActual);
                addAuditHistory.setRelatedId(pcbaLineId);
                auditHistoryDao.addAuditHistory(addAuditHistory);*/

                // 发送邮件通知
                try {
                    /*List<User> userList = new ArrayList<>();
                    Integer pcbaCompanyId = oldPcbaLine.getPcbaCompanyId();
                    if (pcbaCompanyId != null) {
                        PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaCompanyId);
                        if (pcbaCompany != null) {
                            String emailOwners5 = pcbaCompany.getEmailOwners5();
                            if (emailOwners5 != null && !"".equals(emailOwners5)) {
                                String[] split = emailOwners5.split(",");
                                for (String s : split) {
                                    if (s.contains("/")) {
                                        String[] strings = s.split("\\/");
                                        if (strings.length == 2) {
                                            String domainAccount = strings[1];
                                            if (domainAccount != null && !"".equals(domainAccount)) {
                                                User u = userDao.getUserInfoByDomainAccount(domainAccount);
                                                if (u != null) {
                                                    userList.add(u);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    List<MailAddress> mailAddressList = new ArrayList<>();
                    for (User user : userList) {
                        MailAddress mailAddress = new MailAddress();
                        mailAddress.setMailAddress(user.getEmail());
                        mailAddress.setType(0);
                        mailAddressList.add(mailAddress);
                    }*/

                    if (paramsStatusActual == 1) {
                        // 审核通过，清空 审核值
                        //lineTechCapacityValueDao.clearValueAudit(pcbaLineId);
                        // 将当前值更新到 audit
                        lineTechCapacityValueDao.returnValueAuditFromValue(pcbaLineId);

                        /*if (mailAddressList.size() > 0) {
                            Result result = thirdApiService.sendMail("", DB1EmailTemplates.LINE_TECH_PARAMS_TITLE_OK, DB1EmailTemplates.LINE_TECH_PARAMS_MAIL_CONTENT_TITLE_OK,
                                    DB1EmailTemplates.LINE_TECH_PARAMS_MAIL_CONTENT_OK, "10086", mailAddressList, null, null, null, null, 2, null);
                            if (result.getCode() == 200) {
                                System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                                System.out.println("整线实际工艺能力审核结果邮件,发送成功");
                            } else {
                                System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                                System.out.println("整线实际工艺能力审核结果邮件,发送失败:" + result.getMsgCn());
                            }
                        }*/
                    } else if (paramsStatusActual == 2) {
                        // 审核未通过，值还原
                        lineTechCapacityValueDao.returnValueFromValueAudit(pcbaLineId);

                        /*if (mailAddressList.size() > 0) {
                            Result result = thirdApiService.sendMail("", DB1EmailTemplates.LINE_TECH_PARAMS_TITLE_NO, DB1EmailTemplates.LINE_TECH_PARAMS_MAIL_CONTENT_TITLE_NO,
                                    DB1EmailTemplates.LINE_TECH_PARAMS_MAIL_CONTENT_NO, "10086", mailAddressList, null, null, null, null, 2, null);
                            if (result.getCode() == 200) {
                                System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                                System.out.println("整线实际工艺能力审核结果邮件,发送成功");
                            } else {
                                System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                                System.out.println("整线实际工艺能力审核结果邮件,发送失败:" + result.getMsgCn());
                            }
                        }*/
                    }

                    // 级联触发 线体的最终状态
                    coreAlgorithmService.cascadeUpdateLineFinalStatus(3, null, null, pcbaLineId);
                } catch (Exception e) {
                    e.printStackTrace();
                    //System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                    //System.out.println("整线实际工艺能力审核结果邮件发送失败");
                }

                return ResultUtil.success(null);
            }
            return ResultUtil.error(500, "操作失败", "Operate Fail", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result copyLine(String pcbaLineIds) {
        try {
            if (pcbaLineIds == null || "".equals(pcbaLineIds)) {
                return ResultUtil.error(500, "缺少参数pcbaLineIds", "Miss Param pcbaLineIds", null);
            }
            Date d = new Date();
            String[] pcbaLineIdsArr = pcbaLineIds.split(",");
            for (String pcbaLineId : pcbaLineIdsArr) {
                PcbaLine pcbaLine = pcbaLineDao.getPcbaLineById(Integer.parseInt(pcbaLineId));
                String pcbaLineNameCn = pcbaLine.getPcbaLineNameCn();
                PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId());
                String pcbaProcessNameCn = pcbaProcess.getPcbaProcessNameCn();
                Integer maxNum = pcbaLineDao.getMaxNumLine(pcbaLine.getPcbaCompanyId(), pcbaLine.getPcbaWorkshopId(), pcbaLine.getPcbaProcessId());

                // 构造新的线体名并复制
                int next = maxNum + 1;
                String newPcbaLineNameCn = pcbaProcessNameCn + " " + next;
                PcbaLine newPcbaLine = new PcbaLine();
                newPcbaLine.setPcbaLineNameCn(newPcbaLineNameCn);
                newPcbaLine.setPcbaLineNameEn(newPcbaLineNameCn);
                newPcbaLine.setCreateTime(d);
                newPcbaLine.setStatus(pcbaLine.getStatus());
                newPcbaLine.setSort(pcbaLine.getSort());
                newPcbaLine.setPcbaCompanyId(pcbaLine.getPcbaCompanyId());
                newPcbaLine.setPcbaWorkshopId(pcbaLine.getPcbaWorkshopId());
                newPcbaLine.setPcbaLineType(pcbaLine.getPcbaLineType());
                newPcbaLine.setPcbaProcessId(pcbaLine.getPcbaProcessId());
                newPcbaLine.setNotes(pcbaLine.getNotes());
                newPcbaLine.setIsFilledDeclare(2);
                newPcbaLine.setIsFilledActual(2);
                newPcbaLine.setParamsStatusBase(3);
                newPcbaLine.setPcbaLineLevel(pcbaLine.getPcbaLineLevel());
                newPcbaLine.setParamsRemarkBase(pcbaLine.getParamsRemarkBase());
                newPcbaLine.setParamsStatusActual(pcbaLine.getParamsStatusActual());
                newPcbaLine.setParamsStatusActual(pcbaLine.getFinalStatus());
                pcbaLineDao.addPcbaLine(newPcbaLine);

                Integer newPcbaLineId = newPcbaLine.getPcbaLineId();

                // 复制线体下设备
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(Integer.parseInt(pcbaLineId));
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    PcbaDevice newPcbaDevice = new PcbaDevice();
                    newPcbaDevice.setPcbaDeviceNameCn(pcbaDevice.getPcbaDeviceNameCn());
                    newPcbaDevice.setPcbaDeviceNameEn(pcbaDevice.getPcbaDeviceNameEn());
                    newPcbaDevice.setCreateTime(d);
                    newPcbaDevice.setStatus(pcbaDevice.getStatus());
                    newPcbaDevice.setPcbaDeviceTypeId(pcbaDevice.getPcbaDeviceTypeId());
                    newPcbaDevice.setSort(pcbaDevice.getSort());
                    newPcbaDevice.setPcbaLineId(newPcbaLineId);
                    newPcbaDevice.setPcbaDeviceResourceId(pcbaDevice.getPcbaDeviceResourceId());
                    newPcbaDevice.setAssetNumber(UUID.randomUUID().toString());
                    newPcbaDevice.setProductTime(pcbaDevice.getProductTime());
                    newPcbaDevice.setPurpose(pcbaDevice.getPurpose());
                    newPcbaDevice.setIsFilledTechParamsActual(2);
                    pcbaDeviceDao.addPcbaDevice(newPcbaDevice);
                }

                //复制线体基线能力
                List<LineBaseCapacityValue> lineBaseCapacityValueList = lineBaseCapacityValueDao.getAllLineBaseCapacityValueByLineId(Integer.parseInt(pcbaLineId));
                for (LineBaseCapacityValue lineBaseCapacityValue : lineBaseCapacityValueList) {
                    LineBaseCapacityValue newLineBaseCapacityValue = new LineBaseCapacityValue();
                    newLineBaseCapacityValue.setLineBaseCapacityParamKey(lineBaseCapacityValue.getLineBaseCapacityParamKey());
                    newLineBaseCapacityValue.setLineBaseCapacityParamName(lineBaseCapacityValue.getLineBaseCapacityParamName());
                    newLineBaseCapacityValue.setPcbaLineId(newPcbaLineId);
                    newLineBaseCapacityValue.setLineBaseCapacityParamValue(lineBaseCapacityValue.getLineBaseCapacityParamValue());
                    newLineBaseCapacityValue.setCreateTime(d);
                    lineBaseCapacityValueDao.addLineBaseCapacityValue(newLineBaseCapacityValue);
                }

                //复制线体工艺能力
                List<LineTechCapacityValue> lineTechCapacityValueList = lineTechCapacityValueDao.getAllLineTechCapacityValueByLineId(Integer.parseInt(pcbaLineId));
                for (LineTechCapacityValue lineTechCapacityValue : lineTechCapacityValueList) {
                    LineTechCapacityValue newLineTechCapacityValue = new LineTechCapacityValue();
                    newLineTechCapacityValue.setLineTechCapacityParamKey(lineTechCapacityValue.getLineTechCapacityParamKey());
                    newLineTechCapacityValue.setLineTechCapacityParamName(lineTechCapacityValue.getLineTechCapacityParamName());
                    newLineTechCapacityValue.setPcbaLineId(newPcbaLineId);
                    newLineTechCapacityValue.setLineTechCapacityParamValue(lineTechCapacityValue.getLineTechCapacityParamValue());
                    newLineTechCapacityValue.setCreateTime(d);
                    newLineTechCapacityValue.setLineTechCapacityParamValueActual(lineTechCapacityValue.getLineTechCapacityParamValueActual());
                    lineTechCapacityValueDao.addLineTechCapacityValue(newLineTechCapacityValue);
                }
            }
            return ResultUtil.success(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getAllSmtLineForPcbaByCompany(Integer pcbaCompanyId) {
        try {
            if (pcbaCompanyId == null || "".equals(pcbaCompanyId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaCompanyId", "Miss Param pcbaCompanyId", null);
            }
            List<PcbaLine> smtLines = new ArrayList<>();
            List<PcbaLine> allPcbaLineForPcba = pcbaLineDao.getAllPcbaLineForPcba(null, pcbaCompanyId, null, null, 1, null, 1, 1, 1, null);
            for (PcbaLine pcbaLine : allPcbaLineForPcba) {
                if (pcbaLine.getPcbaLineType() == 1) {
                    pcbaLine.setPcbaWorkshop(pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId()));
                    smtLines.add(pcbaLine);
                }
            }
            return ResultUtil.success(smtLines);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result auditPcbaLineParamBase(Integer pcbaLineId, Integer paramsStatusBase, String paramsRemarkBase) {
        try {
            if (pcbaLineId == null || "".equals(pcbaLineId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaLineId", "Miss Param pcbaLineId", null);
            }
            PcbaLine oldPcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);
            Integer isFirstCreate = oldPcbaLine.getIsFirstCreate() != null ? oldPcbaLine.getIsFirstCreate() : 2;
            Integer integer = pcbaLineDao.auditPcbaLineParamBase(pcbaLineId, paramsStatusBase, paramsRemarkBase);
            if (integer > 0) {
            /*<p>1、如果`审核通过`，则会触发以下联动</p>
            <div>&nbsp;&nbsp;&nbsp;1）将当前审核通过的线体/设备记录到临时表，用于下次修改做对比。</div>
            <div>&nbsp;&nbsp;&nbsp;2）将线体/设备信息替换成最新的</div>
            <div>&nbsp;&nbsp;&nbsp;3）重新计算线体的整线基线能力，若值有改变且该值涉及到线体的整线宣称能力，则将线体的整线宣称能力的状态改为`待确认`。如果该值不涉及到线体的整线宣称能力，则无需联动</div>
            <p>2、如果`审核不通过`，则会触发以下联动</p>
            <div>&nbsp;&nbsp;&nbsp;1）将线体/设备信息还原成修改前的</div>*/
                if (paramsStatusBase == 1) {

                    // 1）将当前审核通过的线体/设备记录到临时表，用于下次修改做对比。
                    // 2）将线体/设备信息替换成最新的修改的
                    // 认证通过的话则记录认证通过时的情况
                    pcbaLineDao.updateLineLevelAudit(oldPcbaLine.getPcbaLineLevel(), pcbaLineId);
                    pcbaLineDao.updateLineNotesAudit(oldPcbaLine.getNotes(), pcbaLineId);

                    // 删除原先的
                    pcbaDeviceAuditDao.deleteByLineId(pcbaLineId);
                    List<PcbaDevice> pcbaDeviceByLine = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLineId);
                    // 再新增
                    for (PcbaDevice pcbaDevice : pcbaDeviceByLine) {
                        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(pcbaDevice);
                        PcbaDeviceAudit pcbaDeviceAudit = JSONObject.toJavaObject(jsonObject, PcbaDeviceAudit.class);
                        pcbaDeviceAuditDao.addPcbaDeviceAudit(pcbaDeviceAudit);
                    }

                    // 3）重新计算线体的整线基线能力，将线体的整线宣称能力的状态改为`待确认`
                    // 线体整线基线能力计算后保存到数据库，存在的话修改，不存在的话新增（这里不涉及到审核）
                    coreAlgorithmService.calcLineBaseCapacity(pcbaLineId);
                    /*Result result = coreAlgorithmService.calcLineBaseCapacity(pcbaLineId);
                    if(result.getCode() == 200){
                        Map<String,Object> map = (Map<String,Object>)result.getData();
                        List<BaseCapacityRule> finalKeyAndValueList = (List<BaseCapacityRule>)map.get("finalKeyAndValueList");
                        List<LineBaseBigType> lineBaseBigTypeList = (List<LineBaseBigType>)map.get("lineBaseBigTypeList");

                        List<TechCapacityRule> techCapacityRuleList = techCapacityRuleDao.getAllTechCapacityRule(null, null, null);
                        for (TechCapacityRule techCapacityRule : techCapacityRuleList) {
                            String lineTechParamKey = techCapacityRule.getLineTechParamKey();
                            String baseCapacityParamKey = techCapacityRule.getBaseCapacityParamKey();
                            Integer techCapacityParamFillType = techCapacityRule.getTechCapacityParamFillType();
                            String techCapacityRuleName = techCapacityRule.getTechCapacityRuleName();

                            String v = "";
                            if(techCapacityParamFillType == 1){
                                for (BaseCapacityRule baseCapacityRule : finalKeyAndValueList) {
                                    if(baseCapacityRule.getLineBaseParamKey().equals(baseCapacityParamKey)){
                                        v = baseCapacityRule.getLineBaseParamValue();
                                        break;
                                    }
                                }
                            }
                            LineTechCapacityValue lineTechCapacityValue = lineTechCapacityValueDao.getLineTechCapacityValueByKeyAndLineId(pcbaLineId, lineTechParamKey);
                            if(lineTechCapacityValue == null){
                                // add
                                LineTechCapacityValue addLineTechCapacityValue = new LineTechCapacityValue();
                                addLineTechCapacityValue.setLineTechCapacityParamKey(lineTechParamKey);
                                addLineTechCapacityValue.setLineTechCapacityParamValue(v);
                                addLineTechCapacityValue.setLineTechCapacityParamName(techCapacityRuleName);
                                addLineTechCapacityValue.setCreateTime(new Date());
                                addLineTechCapacityValue.setPcbaLineId(pcbaLineId);
                                lineTechCapacityValueDao.addLineTechCapacityValue(addLineTechCapacityValue);
                            }else{
                                // update
                                Integer lineTechCapacityValueId = lineTechCapacityValue.getLineTechCapacityValueId();
                                LineTechCapacityValue updateLineTechCapacityValue = new LineTechCapacityValue();
                                updateLineTechCapacityValue.setLineTechCapacityParamKey(lineTechParamKey);
                                if(techCapacityParamFillType == 1){
                                    updateLineTechCapacityValue.setLineTechCapacityParamValue(v);
                                }
                                updateLineTechCapacityValue.setLineTechCapacityParamName(techCapacityRuleName);
                                updateLineTechCapacityValue.setUpdateTime(new Date());
                                updateLineTechCapacityValue.setPcbaLineId(pcbaLineId);
                                updateLineTechCapacityValue.setLineTechCapacityValueId(lineTechCapacityValueId);
                                lineTechCapacityValueDao.updateLineTechCapacityValue(updateLineTechCapacityValue);
                            }
                        }
                        // 修改整线宣称能力的状态为`待确认`
                        pcbaLineDao.updatePcbaLineLockDeclare(pcbaLineId, 2);
                    }*/
                    pcbaLineDao.updatePcbaLineLockDeclare(pcbaLineId, 2);
                }

                if (paramsStatusBase == 2) {
                    // 审核未通过
                    // 1）若线体为首次创建的，则审核不通过不还原；否则将线体/设备信息还原成修改前的
                    if(isFirstCreate == 1){
                        // 首次创建
                        // 将 当前记录 存入临时表，同时清空 首次创建标识
                        pcbaLineDao.updateLineLevelAudit(oldPcbaLine.getPcbaLineLevel(), pcbaLineId);
                        pcbaLineDao.updateLineNotesAudit(oldPcbaLine.getNotes(), pcbaLineId);
                        pcbaDeviceAuditDao.deleteByLineId(pcbaLineId);
                        List<PcbaDevice> pcbaDeviceByLine = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLineId);
                        for (PcbaDevice pcbaDevice : pcbaDeviceByLine) {
                            JSONObject jsonObject = (JSONObject) JSONObject.toJSON(pcbaDevice);
                            PcbaDeviceAudit pcbaDeviceAudit = JSONObject.toJavaObject(jsonObject, PcbaDeviceAudit.class);
                            pcbaDeviceAuditDao.addPcbaDeviceAudit(pcbaDeviceAudit);
                        }

                        pcbaLineDao.updatePcbaLineIsFirstCreate(oldPcbaLine.getPcbaLineId(), 2);
                    }else{
                        // 非首次创建
                        pcbaLineDao.returnValueFromValueAudit(pcbaLineId);

                        // 设备列表也要还原
                        List<PcbaDeviceAudit> pcbaDeviceAuditList = pcbaDeviceAuditDao.getAllPcbaDeviceAuditByLine(pcbaLineId);
                        List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLineId);
                        for (PcbaDeviceAudit pcbaDeviceAudit : pcbaDeviceAuditList) {
                            PcbaDevice pcbaDevice = pcbaDeviceDao.getById(pcbaDeviceAudit.getPcbaDeviceId());
                            if (pcbaDevice == null) {
                                // 新增
                                JSONObject jsonObject = (JSONObject) JSONObject.toJSON(pcbaDeviceAudit);
                                PcbaDevice p = JSONObject.toJavaObject(jsonObject, PcbaDevice.class);
                                pcbaDeviceDao.addPcbaDeviceByAllParams(p);
                            }
                        }
                        for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                            PcbaDeviceAudit pcbaDeviceAudit = pcbaDeviceAuditDao.getById(pcbaDevice.getPcbaDeviceId());
                            if (pcbaDeviceAudit == null) {
                                // 删除
                                pcbaDeviceDao.deleteById(pcbaDevice.getPcbaDeviceId());
                            } else {
                                // 更新
                                pcbaDevice.setSort(pcbaDeviceAudit.getSort());
                                pcbaDevice.setAssetNumber(pcbaDeviceAudit.getAssetNumber());
                                pcbaDevice.setPurpose(pcbaDeviceAudit.getPurpose());
                                pcbaDevice.setProductTime(pcbaDeviceAudit.getProductTime());
                                pcbaDeviceDao.updatePcbaDevice(pcbaDevice);
                            }
                        }
                    }
                }

                if (paramsStatusBase == 3) {
                    //发送邮件
                    try {
                        String companyName = "";
                        String workshopName = "";
                        String lineName = "";
                        List<User> userList = new ArrayList<>();
                        PcbaLine pcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);
                        if (pcbaLine != null) {
                            PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId());
                            PcbaWorkshop pcbaWorkshop = pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId());
                            if(pcbaWorkshop != null){
                                workshopName = pcbaWorkshop.getPcbaWorkshopNameCn();
                            }
                            lineName = pcbaLine.getPcbaLineNameCn();
                            if (pcbaCompany != null) {
                                companyName = pcbaCompany.getPcbaCompanyNameCn();
                                String emailOwners5 = pcbaCompany.getEmailOwners5();
                                if (emailOwners5 != null && !"".equals(emailOwners5)) {
                                    String[] split = emailOwners5.split(",");
                                    for (String s : split) {
                                        if (s.contains("/")) {
                                            String[] strings = s.split("\\/");
                                            if (strings.length == 2) {
                                                String domainAccount = strings[1];
                                                if (domainAccount != null && !"".equals(domainAccount)) {
                                                    User u = userDao.getUserInfoByDomainAccount(domainAccount);
                                                    if (u != null) {
                                                        userList.add(u);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        List<MailAddress> mailAddressList = new ArrayList<>();
                        for (User user : userList) {
                            if(user.getEmail().contains(",")){
                                String[] emailsArr = user.getEmail().split(",");
                                for (String email : emailsArr) {
                                    MailAddress mailAddress = new MailAddress();
                                    mailAddress.setMailAddress(email);
                                    mailAddress.setType(0);
                                    mailAddressList.add(mailAddress);
                                }
                            }else{
                                MailAddress mailAddress = new MailAddress();
                                mailAddress.setMailAddress(user.getEmail());
                                mailAddress.setType(0);
                                mailAddressList.add(mailAddress);
                            }
                        }

                        String mailContent = "<html><body>" +
                                "<p>主题：" + DB1EmailTemplates.LINE_DEVICE_CONFIG_MAIL_TITLE + "</p>" +
                                "<p>相关线体：" + companyName + "/" + workshopName + "/" + lineName + "</p>" +
                                "<p>网页链接：" + "<a href='" + trustedRedirectUri + DB1EmailTemplates.LINE_DEVICE_CONFIG_WEB_URL + "'>点击跳转</a>" +  "</p>" +
                                "</html></body>";

                        if (mailAddressList.size() > 0) {
                            Result result = thirdApiService.sendMail("", DB1EmailTemplates.LINE_DEVICE_CONFIG_MAIL_TITLE, DB1EmailTemplates.LINE_DEVICE_CONFIG_MAIL_CONTENT_TITLE,
                                    mailContent, "10086", mailAddressList, null, null, null, null, 2, null);
                            if (result.getCode() == 200) {
                                System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                                System.out.println("线体设备创建维护邮件,发送成功");
                            } else {
                                System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                                System.out.println("线体设备创建维护邮件,发送失败:" + result.getMsgCn());
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        System.out.println(CommonUtils.formatCurrentTime() + "==========================================");
                        System.out.println("线体设备创建维护邮件：" + e.getMessage());
                    }
                }

                // 级联触发 线体的最终状态
                coreAlgorithmService.cascadeUpdateLineFinalStatus(3, null, null, pcbaLineId);

                return ResultUtil.success(null);
            }
            return ResultUtil.error(500, "操作失败", "Operate Fail", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getAllNeedToLoopCloseLine(String data) {
        try {

            JSONObject jsonObject = JSONObject.parseObject(data);
            String pcbaLineNames = jsonObject.getString("pcbaLineNames");
            String chooseCompanyAndWorkshop = jsonObject.getString("chooseCompanyAndWorkshop");
            String pcbaProcessIds = jsonObject.getString("pcbaProcessIds");
            String status = jsonObject.getString("status");

            List<String> pbcaLineNameList = new ArrayList<>();
            List<String> pcbaWorkshopIdList = new ArrayList<>();
            List<String> pcbaProcessIdList = new ArrayList<>();
            if (pcbaLineNames != null && !"".equals(pcbaLineNames)) {
                String[] split = pcbaLineNames.split(",");
                pbcaLineNameList.addAll(Arrays.asList(split));
            }
            if (chooseCompanyAndWorkshop != null && !"".equals(chooseCompanyAndWorkshop)) {
                JSONArray jsonArray = JSONArray.parseArray(chooseCompanyAndWorkshop);
                for (int a = 0; a < jsonArray.size(); a++) {
                    JSONArray jsonArray1 = jsonArray.getJSONArray(a);
                    if (jsonArray1.size() == 2) {
                        pcbaWorkshopIdList.add(jsonArray1.get(1).toString());
                    }
                }

            }
            if (pcbaProcessIds != null && !"".equals(pcbaProcessIds)) {
                String[] split = pcbaProcessIds.split(",");
                pcbaProcessIdList.addAll(Arrays.asList(split));
            }

            List<Integer> companyIdList = strToCompanys.getPcbaCompanyIdListFromStr();

            // 高端线体的列表
            List<PcbaLine> highLineList = new ArrayList<>();

            List<PcbaLine> list = pcbaLineDao.getAllPcbaLineView(pbcaLineNameList, pcbaWorkshopIdList, pcbaProcessIdList, Integer.parseInt(status), 1, null, null, companyIdList);
            for (PcbaLine pcbaLine : list) {
                LineLevel lineLevel = lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevel());
                if (lineLevel != null && lineLevel.getLineLevelName().contains("高端")) {
                    highLineList.add(pcbaLine);
                }
            }
            for (PcbaLine pcbaLine : highLineList) {
                pcbaLine.setLineLevel(lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevel()));
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                pcbaLine.setPcbaDeviceNums(pcbaDeviceList.size());
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    List<String> loopCloseFilesList = new ArrayList<>();
                    List<String> ageCloseFilesList = new ArrayList<>();
                    if(pcbaDevice.getLoopCloseFiles() != null && !"".equals(pcbaDevice.getLoopCloseFiles())){
                        String[] split = pcbaDevice.getLoopCloseFiles().split(",");
                        loopCloseFilesList.addAll(Arrays.asList(split));
                    }
                    pcbaDevice.setLoopCloseFilesList(loopCloseFilesList);
                    if(pcbaDevice.getAgeCloseFiles() != null && !"".equals(pcbaDevice.getAgeCloseFiles())){
                        String[] split = pcbaDevice.getAgeCloseFiles().split(",");
                        ageCloseFilesList.addAll(Arrays.asList(split));
                    }
                    pcbaDevice.setAgeCloseFilesList(ageCloseFilesList);
                    if (pcbaDevice.getProductTime() != null && !"".equals(pcbaDevice.getProductTime().toString())) {
                        Date d1 = new Date();
                        LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        LocalDate ld2 = pcbaDevice.getProductTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        double age = CommonUtils.calculateYearDifference(ld2, ld1);
                        pcbaDevice.setAge(age);

                        Result result = coreAlgorithmService.calcIsOverSixYearInHighLine(pcbaDevice, pcbaLine.getPcbaLineLevel());
                        if (result.getCode() == 200) {
                            int i = Integer.parseInt(result.getData().toString());
                            pcbaDevice.setIsOverSixYearInHighLine(i);
                        }
                    }
                    PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                    if (pcbaDeviceResource != null) {
                        pcbaDeviceResource.setBrand(brandDao.getBrandById(pcbaDeviceResource.getBrandId()));
                        pcbaDeviceResource.setBrandType(brandTypeDao.getBrandTypeById(pcbaDeviceResource.getBrandTypeId()));
                        pcbaDevice.setPcbaDeviceResource(pcbaDeviceResource);
                        pcbaDevice.setPcbaDeviceType(pcbaDeviceTypeDao.getById(pcbaDevice.getPcbaDeviceTypeId()));
                    }
                }
                int isOverSixYearInHighLine = 2;
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    if (pcbaDevice.getIsOverSixYearInHighLine() != null && pcbaDevice.getIsOverSixYearInHighLine() == 1) {
                        isOverSixYearInHighLine = 1;
                        break;
                    }
                }
                pcbaLine.setPcbaDeviceList(pcbaDeviceList);
                pcbaLine.setIsOverSixYearInHighLine(isOverSixYearInHighLine);
                PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId());
                PcbaWorkshop pcbaWorkshop = pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId());
                PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId());
                pcbaLine.setPcbaCompany(pcbaCompany);
                pcbaLine.setPcbaWorkshop(pcbaWorkshop);
                pcbaLine.setPcbaProcess(pcbaProcess);
            }
            List<PcbaLine> finalList = new ArrayList<>();
            for (PcbaLine pcbaLine : highLineList) {
                if (pcbaLine.getIsOverSixYearInHighLine() == 1) {
                    finalList.add(pcbaLine);
                }
            }
            return ResultUtil.success(finalList);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result exportPcbaLineAndDeviceParamsExcel(String pcbaLineIds, Integer type, String operateType) {
        try {
            if (type == null || "".equals(type.toString())) {
                return ResultUtil.error(500, "缺少参数type", "Miss Param type", null);
            }
            if (operateType == null || "".equals(operateType)) {
                return ResultUtil.error(500, "缺少参数operateType", "Miss Param operateType", null);
            }
            if (type == 2) {
                if (pcbaLineIds == null || "".equals(pcbaLineIds)) {
                    return ResultUtil.error(500, "缺少参数pcbaLineIds", "Miss Param pcbaLineIds", null);
                }
            }
            List<Integer> companyIdList = strToCompanys.getPcbaCompanyIdListFromStr();
            List<PcbaLine> pcbaLineList = new ArrayList<>();
            if (type == 1) {
                pcbaLineList = pcbaLineDao.getAllPcbaLine(null, null, null, null, null, null, null, null, null, null, companyIdList);
            } else {
                String[] pcbaLineIdArr = pcbaLineIds.split(",");
                for (String pcbaLineIdStr : pcbaLineIdArr) {
                    Integer pcbaLineId = Integer.parseInt(pcbaLineIdStr);
                    PcbaLine pcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);
                    if (pcbaLine != null) {
                        pcbaLineList.add(pcbaLine);
                    }
                }
            }

            List<PcbaLine> finalPcbaLineList = new ArrayList<>();
            for (PcbaLine pcbaLine : pcbaLineList) {
                Integer pcbaLineId = pcbaLine.getPcbaLineId();
                Integer pcbaLineType = pcbaLine.getPcbaLineType();
                Integer pcbaLineLevel = pcbaLine.getPcbaLineLevel();
                pcbaLine.setPcbaCompany(pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId()));
                pcbaLine.setPcbaWorkshop(pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId()));
                pcbaLine.setLineLevel(lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevel()));
                pcbaLine.setPcbaProcess(pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId()));
                if (pcbaLineType == 1) {
                    // SMT 导出线体参数需要区分是SMT还是自动化线体，不仅需要导出工艺整线能力，还要导出设备工艺能力
                    LineTechBigType lineTechBigType_ = null;
                    List<LineTechBigType> lineTechBigTypeList = lineTechBigTypeDao.getAllLineTechBigType(null);
                    for (LineTechBigType lineTechBigType : lineTechBigTypeList) {
                        String lineLevelIds = lineTechBigType.getLineLevelIds();
                        //Integer lineTechBigTypeId = lineTechBigType.getLineTechBigTypeId();
                        if (lineLevelIds.contains(pcbaLineLevel.toString())) {
                            lineTechBigType_ = lineTechBigType;
                            break;
                        }
                    }
                    if (lineTechBigType_ != null) {
                        Integer lineTechBigTypeId = lineTechBigType_.getLineTechBigTypeId();
                        List<LineTechSmallType> lineTechSmallTypeList = lineTechSmallTypeDao.getAllLineTechSmallTypeByBigType(null, lineTechBigTypeId);
                        for (LineTechSmallType lineTechSmallType : lineTechSmallTypeList) {
                            Integer lineTechSmallTypeId = lineTechSmallType.getLineTechSmallTypeId();
                            List<TechCapacityRule> techCapacityRuleList = techCapacityRuleDao.getAllTechCapacityRule(null, lineTechBigTypeId, lineTechSmallTypeId);
                            // 处理线体的宣称能力和实际能力
                            for (TechCapacityRule techCapacityRule : techCapacityRuleList) {
                                String lineTechParamKey = techCapacityRule.getLineTechParamKey();
                                LineTechCapacityValue lineTechCapacityValue = lineTechCapacityValueDao.getLineTechCapacityValueByKeyAndLineId(pcbaLineId, lineTechParamKey);
                                if (lineTechCapacityValue != null) {
                                    techCapacityRule.setDeclareValue(lineTechCapacityValue.getLineTechCapacityParamValue());
                                    techCapacityRule.setActualValue(lineTechCapacityValue.getLineTechCapacityParamValueActual());
                                } else {
                                    techCapacityRule.setDeclareValue("");
                                    techCapacityRule.setActualValue("");
                                }
                            }
                            lineTechSmallType.setTechCapacityRuleList(techCapacityRuleList);
                        }
                        lineTechBigType_.setLineTechSmallTypeList(lineTechSmallTypeList);
                    }
                    pcbaLine.setLineTechBigType(lineTechBigType_);

                    List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLineId);
                    for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                        Integer pcbaDeviceResourceId = pcbaDevice.getPcbaDeviceResourceId();
                        Integer pcbaDeviceTypeId = pcbaDevice.getPcbaDeviceTypeId();
                        Integer pcbaDeviceId = pcbaDevice.getPcbaDeviceId();
                        pcbaDevice.setPcbaDeviceType(pcbaDeviceTypeDao.getById(pcbaDeviceTypeId));
                        List<TechDeviceParamType> techDeviceParamTypeList = techDeviceParamTypeDao.getAllTechDeviceParamTypeByDeviceType(pcbaDeviceTypeId, null);
                        for (TechDeviceParamType techDeviceParamType : techDeviceParamTypeList) {
                            Integer techDeviceParamTypeId = techDeviceParamType.getTechDeviceParamTypeId();
                            List<TechDeviceParam> techDeviceParamList = techDeviceParamDao.getAllTechDeviceParam(pcbaDeviceTypeId, techDeviceParamTypeId, null);
                            for (TechDeviceParam techDeviceParam : techDeviceParamList) {
                                String techDeviceParamKey = techDeviceParam.getTechDeviceParamKey();
                                // 处理设备资源宣称能力和实际能力
                                PcbaDeviceRelatedTechParam pcbaDeviceRelatedTechParam = pcbaDeviceRelatedTechParamDao.getPcbaDeviceRelatedTechParamByKeyAndDeviceResourceId(techDeviceParamKey, pcbaDeviceResourceId);
                                if (pcbaDeviceRelatedTechParam != null) {
                                    techDeviceParam.setDeclareValue(pcbaDeviceRelatedTechParam.getTechDeviceParamValue());
                                } else {
                                    techDeviceParam.setDeclareValue(null);
                                }
                                PcbaDeviceRelatedTechParamActual pcbaDeviceRelatedTechParamActual = pcbaDeviceRelatedTechParamActualDao.getPcbaDeviceRelatedTechParamActualByPcbaDeviceIdAndKey(pcbaDeviceId, techDeviceParamKey);
                                if (pcbaDeviceRelatedTechParamActual != null) {
                                    techDeviceParam.setActualValue(pcbaDeviceRelatedTechParamActual.getTechDeviceParamValue());
                                } else {
                                    techDeviceParam.setActualValue(null);
                                }
                            }
                            techDeviceParamType.setTechDeviceParamList(techDeviceParamList);
                        }
                        pcbaDevice.setTechDeviceParamTypeList(techDeviceParamTypeList);
                    }
                    pcbaLine.setPcbaDeviceList(pcbaDeviceList);
                } else {
                    // 非SMT无工艺整线能力，直接导出设备工艺能力即可
                    List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLineId);
                    for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                        Integer pcbaDeviceResourceId = pcbaDevice.getPcbaDeviceResourceId();
                        Integer pcbaDeviceTypeId = pcbaDevice.getPcbaDeviceTypeId();
                        Integer pcbaDeviceId = pcbaDevice.getPcbaDeviceId();
                        pcbaDevice.setPcbaDeviceType(pcbaDeviceTypeDao.getById(pcbaDeviceTypeId));
                        List<TechDeviceParamType> techDeviceParamTypeList = techDeviceParamTypeDao.getAllTechDeviceParamTypeByDeviceType(pcbaDeviceTypeId, null);
                        for (TechDeviceParamType techDeviceParamType : techDeviceParamTypeList) {
                            Integer techDeviceParamTypeId = techDeviceParamType.getTechDeviceParamTypeId();
                            List<TechDeviceParam> techDeviceParamList = techDeviceParamDao.getAllTechDeviceParam(pcbaDeviceTypeId, techDeviceParamTypeId, null);
                            for (TechDeviceParam techDeviceParam : techDeviceParamList) {
                                String techDeviceParamKey = techDeviceParam.getTechDeviceParamKey();
                                // 处理设备资源宣称能力和实际能力
                                PcbaDeviceRelatedTechParam pcbaDeviceRelatedTechParam = pcbaDeviceRelatedTechParamDao.getPcbaDeviceRelatedTechParamByKeyAndDeviceResourceId(techDeviceParamKey, pcbaDeviceResourceId);
                                if (pcbaDeviceRelatedTechParam != null) {
                                    techDeviceParam.setDeclareValue(pcbaDeviceRelatedTechParam.getTechDeviceParamValue());
                                } else {
                                    techDeviceParam.setDeclareValue(null);
                                }
                                PcbaDeviceRelatedTechParamActual pcbaDeviceRelatedTechParamActual = pcbaDeviceRelatedTechParamActualDao.getPcbaDeviceRelatedTechParamActualByPcbaDeviceIdAndKey(pcbaDeviceId, techDeviceParamKey);
                                if (pcbaDeviceRelatedTechParamActual != null) {
                                    techDeviceParam.setActualValue(pcbaDeviceRelatedTechParamActual.getTechDeviceParamValue());
                                } else {
                                    techDeviceParam.setActualValue(null);
                                }
                            }
                            techDeviceParamType.setTechDeviceParamList(techDeviceParamList);
                        }
                        pcbaDevice.setTechDeviceParamTypeList(techDeviceParamTypeList);
                    }
                    pcbaLine.setPcbaDeviceList(pcbaDeviceList);
                }
                finalPcbaLineList.add(pcbaLine);
            }

            if("for_admin".equals(operateType)){
                // 根据 pcbaLineList结构渲染出Excel
                // 创建工作簿对象
                Workbook workbook = new XSSFWorkbook();
                String excelFileName = "线体设备工艺能力表";
                for (PcbaLine p : finalPcbaLineList) {
                    int index = 0;
                    int beginIndex1 = 1;
                    int beginIndex2 = 1;
                    // XX工厂线体设备整线能力反馈报告
                    String excelName = p.getPcbaCompany().getPcbaCompanyNameCn() + "工艺能力（" + p.getPcbaLineNameCn() + "）" + UUID.randomUUID().toString();
                    // 创建工作表对象
                    Sheet sheet = workbook.createSheet(CommonUtils.handleSheetName(excelName));

                    CellStyle bodyContextCellStyle = workbook.createCellStyle();
                    DataFormat format = workbook.createDataFormat();
                    bodyContextCellStyle.setDataFormat(format.getFormat("@"));
                    bodyContextCellStyle.setBorderBottom(BorderStyle.THIN);
                    bodyContextCellStyle.setBorderLeft(BorderStyle.THIN);
                    bodyContextCellStyle.setBorderRight(BorderStyle.THIN);
                    bodyContextCellStyle.setBorderTop(BorderStyle.THIN);
                    bodyContextCellStyle.setAlignment(HorizontalAlignment.LEFT);
                    bodyContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

                    CellStyle titleContextCellStyle = workbook.createCellStyle();
                    titleContextCellStyle.setBorderBottom(BorderStyle.THIN);
                    titleContextCellStyle.setBorderLeft(BorderStyle.THIN);
                    titleContextCellStyle.setBorderRight(BorderStyle.THIN);
                    titleContextCellStyle.setBorderTop(BorderStyle.THIN);
                    titleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
                    titleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
                    // 设置背景色为红色
                    titleContextCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
                    // 创建字体对象
                    Font titleFont = workbook.createFont();
                    // 设置字体颜色为蓝色
                    titleFont.setColor(IndexedColors.WHITE.getIndex());
                    titleFont.setBold(true);
                    titleContextCellStyle.setFont(titleFont);
                    // 设置填充类型为填充实体背景
                    titleContextCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                    Row row = sheet.createRow(0);
                    Cell cell;

                    List<Map<String, Object>> titleList = new ArrayList<>();
                    Map<String, Object> map = new HashMap<>();
                    map = new HashMap<>();
                    map.put("title", "线体名称");
                    map.put("width", 5000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "线体类型");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "工厂");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "车间");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "工序");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "外协厂实际车间名称");
                    map.put("width", 10000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "项目大类");
                    map.put("width", 5000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "项目小类");
                    map.put("width", 5000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "能力项");
                    map.put("width", 12000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "key");
                    map.put("width", 5000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "规则逻辑/数据来源");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "实际能力是否等于宣称能力");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "宣称值");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "实际值");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "认证开始时间");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "认证结束时间");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "认证状态");
                    map.put("width", 8000);
                    titleList.add(map);
                    row = sheet.createRow(0);
                    for (int a = 0; a < titleList.size(); a++) {
                        sheet.setColumnWidth(a, Integer.parseInt(titleList.get(a).get("width").toString()));
                        // sheet.setDefaultRowHeight((short)450);
                        cell = row.createCell(a);
                        // 向单元格中写入数据
                        cell.setCellValue(titleList.get(a).get("title").toString());
                        cell.setCellStyle(titleContextCellStyle);
                    }
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    LineTechBigType lineTechBigType = p.getLineTechBigType();
                    if (lineTechBigType != null) {
                        if (lineTechBigType.getLineTechSmallTypeList() != null && lineTechBigType.getLineTechSmallTypeList().size() > 0) {
                            for (LineTechSmallType lineTechSmallType : lineTechBigType.getLineTechSmallTypeList()) {
                                if (lineTechSmallType.getTechCapacityRuleList() != null && lineTechSmallType.getTechCapacityRuleList().size() > 0) {
                                    for (TechCapacityRule techCapacityRule : lineTechSmallType.getTechCapacityRuleList()) {
                                        index++;
                                        Row row_ = sheet.createRow(index);

                                        // 线体名称
                                        Cell cell_ = row_.createCell(0);
                                        cell_.setCellValue(p.getPcbaLineNameCn());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 线体类型
                                        cell_ = row_.createCell(1);
                                        cell_.setCellValue(p.getLineLevel() != null ? p.getLineLevel().getLineLevelName() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 工厂
                                        cell_ = row_.createCell(2);
                                        cell_.setCellValue(p.getPcbaCompany() != null ? p.getPcbaCompany().getPcbaCompanyNameCn() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 车间
                                        cell_ = row_.createCell(3);
                                        cell_.setCellValue(p.getPcbaWorkshop() != null ? p.getPcbaWorkshop().getPcbaWorkshopNameCn() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 工序
                                        cell_ = row_.createCell(4);
                                        cell_.setCellValue(p.getPcbaProcess() != null ? p.getPcbaProcess().getPcbaProcessNameCn() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 外协厂实际车间名称
                                        cell_ = row_.createCell(5);
                                        cell_.setCellValue(p.getNotes() != null ? p.getNotes() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 项目大类
                                        cell_ = row_.createCell(6);
                                        cell_.setCellValue(lineTechBigType.getLineTechBigTypeName());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 项目小类
                                        cell_ = row_.createCell(7);
                                        cell_.setCellValue(lineTechSmallType.getLineTechSmallTypeName());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 能力项
                                        cell_ = row_.createCell(8);
                                        cell_.setCellValue(techCapacityRule.getTechCapacityRuleName());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // key
                                        cell_ = row_.createCell(9);
                                        cell_.setCellValue(techCapacityRule.getLineTechParamKey());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 规则逻辑
                                        //1:来自于基线对应值
                                        //2：手动填
                                        //3：bis
                                        //4：取多个设备基线能力的最大值
                                        //5：取多个设备基线能力的最小值[前两位]
                                        //6：取多个设备基线能力的最小值

                                        cell_ = row_.createCell(10);
                                        cell_.setCellValue(techCapacityRule.getTechCapacityRuleType() != null ?
                                                (techCapacityRule.getTechCapacityRuleType() == 1 ? "来自于基线对应值" :
                                                        (techCapacityRule.getTechCapacityRuleType() == 2 ? "手填" :
                                                                (techCapacityRule.getTechCapacityRuleType() == 3 ? "bis" :
                                                                        (techCapacityRule.getTechCapacityRuleType() == 4 ? "取多个设备基线能力的最大值" :
                                                                                (techCapacityRule.getTechCapacityRuleType() == 5 ? "取多个设备基线能力的最小值[前两位]" :
                                                                                        (techCapacityRule.getTechCapacityRuleType() == 6 ? "取多个设备基线能力的最小值" : "")))))) : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 实际能力是否等于宣称能力
                                        cell_ = row_.createCell(11);
                                        cell_.setCellValue((techCapacityRule.getActualEqualDeclare() != null && techCapacityRule.getActualEqualDeclare() == 1) ? "等于" : "不等于");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 宣称值
                                        cell_ = row_.createCell(12);
                                        cell_.setCellValue(techCapacityRule.getDeclareValue() != null ? techCapacityRule.getDeclareValue() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 实际值
                                        cell_ = row_.createCell(13);
                                        cell_.setCellValue(techCapacityRule.getActualValue() != null ? techCapacityRule.getActualValue() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 认证开始时间
                                        String beginTimeActualStr = "";
                                        try {
                                            beginTimeActualStr = sdf.format(p.getBeginTimeActual());
                                        } catch (Exception e) {

                                        }

                                        cell_ = row_.createCell(14);
                                        cell_.setCellValue(beginTimeActualStr);
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 认证结束时间
                                        String endTimeActualStr = "";
                                        try {
                                            endTimeActualStr = sdf.format(p.getEndTimeActual());
                                        } catch (Exception e) {

                                        }
                                        cell_ = row_.createCell(15);
                                        cell_.setCellValue(endTimeActualStr);
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 认证状态
                                        cell_ = row_.createCell(16);
                                        cell_.setCellValue(p.getParamsStatusActual() != null ? (
                                                p.getParamsStatusActual() == 1 ? "认证通过" : (
                                                        p.getParamsStatusActual() == 2 ? "认证未通过" : (
                                                                p.getParamsStatusActual() == 3 ? "认证中" : (
                                                                        p.getParamsStatusActual() == 4 ? "待提交认证" : (
                                                                                p.getParamsStatusActual() == 5 ? "超出有效期" : (
                                                                                        p.getParamsStatusActual() == 6 ? "存在设备认证过期" : "待提交认证"
                                                                                )
                                                                        )
                                                                )
                                                        )
                                                )
                                        ) : "待提交认证");
                                        cell_.setCellStyle(bodyContextCellStyle);
                                    }
                                    if (lineTechSmallType.getTechCapacityRuleList().size() > 1) {
                                        if (index > beginIndex2) {
                                            sheet.addMergedRegion(new CellRangeAddress(beginIndex2, index, 7, 7));
                                            beginIndex2 = index + 1;
                                        } else {
                                            beginIndex2 = index + 1;
                                        }
                                    } else {
                                        beginIndex2 = index + 1;
                                    }
                                }
                            }
                            //if(lineBaseBigType.getLineBaseSmallTypeList().size() > 1){
                            if (index > beginIndex1) {
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 0, 0));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 1, 1));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 2, 2));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 3, 3));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 4, 4));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 5, 5));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 6, 6));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 14, 14));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 15, 15));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 16, 16));
                                beginIndex1 = index + 1;
                            } else {
                                beginIndex1 = index + 1;
                            }
                        /*}else{
                            beginIndex1 = index + 1;
                        }*/
                        }
                    } else {
                        index++;
                        Row row_ = sheet.createRow(index);

                        // 线体名称
                        Cell cell_ = row_.createCell(0);
                        cell_.setCellValue(p.getPcbaLineNameCn());
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 线体类型
                        cell_ = row_.createCell(1);
                        cell_.setCellValue(p.getLineLevel() != null ? p.getLineLevel().getLineLevelName() : "");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 工厂
                        cell_ = row_.createCell(2);
                        cell_.setCellValue(p.getPcbaCompany() != null ? p.getPcbaCompany().getPcbaCompanyNameCn() : "");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 车间
                        cell_ = row_.createCell(3);
                        cell_.setCellValue(p.getPcbaWorkshop() != null ? p.getPcbaWorkshop().getPcbaWorkshopNameCn() : "");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 工序
                        cell_ = row_.createCell(4);
                        cell_.setCellValue(p.getPcbaProcess() != null ? p.getPcbaProcess().getPcbaProcessNameCn() : "");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 外协厂实际车间名称
                        cell_ = row_.createCell(5);
                        cell_.setCellValue(p.getNotes() != null ? p.getNotes() : "");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 项目大类
                        cell_ = row_.createCell(6);
                        cell_.setCellValue("NA");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 项目小类
                        cell_ = row_.createCell(7);
                        cell_.setCellValue("NA");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 能力项
                        cell_ = row_.createCell(8);
                        cell_.setCellValue("NA");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // key
                        cell_ = row_.createCell(9);
                        cell_.setCellValue("NA");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 规则逻辑
                        cell_ = row_.createCell(10);
                        cell_.setCellValue("NA");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 实际能力是否等于宣称能力
                        cell_ = row_.createCell(11);
                        cell_.setCellValue("NA");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 宣称值
                        cell_ = row_.createCell(12);
                        cell_.setCellValue("NA");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 实际值
                        cell_ = row_.createCell(13);
                        cell_.setCellValue("NA");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 认证开始时间
                        String beginTimeActualStr = "";
                        try {
                            beginTimeActualStr = sdf.format(p.getBeginTimeActual());
                        } catch (Exception e) {

                        }

                        cell_ = row_.createCell(14);
                        cell_.setCellValue(beginTimeActualStr);
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 认证结束时间
                        String endTimeActualStr = "";
                        try {
                            endTimeActualStr = sdf.format(p.getEndTimeActual());
                        } catch (Exception e) {

                        }
                        cell_ = row_.createCell(15);
                        cell_.setCellValue(endTimeActualStr);
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 认证状态
                        cell_ = row_.createCell(16);
                        cell_.setCellValue(p.getParamsStatusActual() != null ? (
                                p.getParamsStatusActual() == 1 ? "认证通过" : (
                                        p.getParamsStatusActual() == 2 ? "认证未通过" : (
                                                p.getParamsStatusActual() == 3 ? "认证中" : (
                                                        p.getParamsStatusActual() == 4 ? "待提交认证" : (
                                                                p.getParamsStatusActual() == 5 ? "超出有效期" : (
                                                                        p.getParamsStatusActual() == 6 ? "存在设备认证过期" : "待提交认证"
                                                                )
                                                        )
                                                )
                                        )
                                )
                        ) : "待提交认证");
                        cell_.setCellStyle(bodyContextCellStyle);
                    }

                    //中间空一行
                    index++;
                    index++;

                    beginIndex1 = index + 1;
                    beginIndex2 = index + 1;

                    // 渲染设备数据列表
                    List<Map<String, Object>> titleList2 = new ArrayList<>();
                    Map<String, Object> map2 = new HashMap<>();
                    map2 = new HashMap<>();
                    map2.put("title", "序号");
                    map2.put("width", 5000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "设备名");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "资产编号");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "用途");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "设备类型");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "工艺大类");
                    map2.put("width", 10000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "能力项");
                    map2.put("width", 12000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "key");
                    map2.put("width", 5000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "字段类型");
                    map2.put("width", 12000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "实际能力是否等于宣称能力");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "宣称值");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "实际值");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "认证开始时间");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "认证结束时间");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "认证状态");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    row = sheet.createRow(index);
                    for (int a = 0; a < titleList2.size(); a++) {
                        sheet.setColumnWidth(a, Integer.parseInt(titleList2.get(a).get("width").toString()));
                        cell = row.createCell(a + 2);
                        // 向单元格中写入数据
                        cell.setCellValue(titleList2.get(a).get("title").toString());
                        cell.setCellStyle(titleContextCellStyle);
                    }

                    int deviceIndex = 0;
                    for (PcbaDevice pcbaDevice : p.getPcbaDeviceList()) {
                        deviceIndex++;
                        if (pcbaDevice.getTechDeviceParamTypeList() != null && pcbaDevice.getTechDeviceParamTypeList().size() > 0) {
                            for (TechDeviceParamType techDeviceParamType : pcbaDevice.getTechDeviceParamTypeList()) {
                                if (techDeviceParamType.getTechDeviceParamList() != null && techDeviceParamType.getTechDeviceParamList().size() > 0) {
                                    for (TechDeviceParam techDeviceParam : techDeviceParamType.getTechDeviceParamList()) {
                                        index++;
                                        Row row_ = sheet.createRow(index);

                                        // 序号
                                        Cell cell_ = row_.createCell(2);
                                        cell_.setCellValue(deviceIndex);
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 设备名
                                        cell_ = row_.createCell(3);
                                        cell_.setCellValue(pcbaDevice.getPcbaDeviceNameCn());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 资产编号
                                        cell_ = row_.createCell(4);
                                        cell_.setCellValue(pcbaDevice.getAssetNumber());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 用途
                                        cell_ = row_.createCell(5);
                                        cell_.setCellValue(pcbaDevice.getPurpose());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 设备类型
                                        cell_ = row_.createCell(6);
                                        cell_.setCellValue(pcbaDevice.getPcbaDeviceType() != null ? pcbaDevice.getPcbaDeviceType().getPcbaDeviceTypeNameCn() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 工艺大类
                                        cell_ = row_.createCell(7);
                                        cell_.setCellValue(techDeviceParamType.getTechDeviceParamTypeName());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 能力项
                                        cell_ = row_.createCell(8);
                                        cell_.setCellValue(techDeviceParam.getTechDeviceParamNameCn());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // key
                                        cell_ = row_.createCell(9);
                                        cell_.setCellValue(techDeviceParam.getTechDeviceParamKey());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 字段类型
                                        //字段类型
                                        //1：普通文本
                                        //2.下拉选择
                                        //3：文件上传
                                        //4：来源基线
                                        //5：取多个基线最小值
                                        //11：数值类型[整数]
                                        //12：数值类型[小数]
                                        cell_ = row_.createCell(10);
                                        cell_.setCellValue(techDeviceParam.getTechDeviceParamFillType() == 1 ? "普通文本" :
                                                (techDeviceParam.getTechDeviceParamFillType() == 2 ? "下拉选择(" + techDeviceParam.getTechDeviceParamOptions() + ")" :
                                                        (techDeviceParam.getTechDeviceParamFillType() == 3 ? "文件上传" :
                                                                (techDeviceParam.getTechDeviceParamFillType() == 4 ? "来源基线" :
                                                                        (techDeviceParam.getTechDeviceParamFillType() == 5 ? "取多个基线最小值" :
                                                                                (techDeviceParam.getTechDeviceParamFillType() == 11 ? "数值类型[整数]" :
                                                                                        (techDeviceParam.getTechDeviceParamFillType() == 12 ? "数值类型[小数]" : "")))))));
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 实际能力是否等于宣称能力
                                        cell_ = row_.createCell(11);
                                        cell_.setCellValue((techDeviceParam.getActualEqualDeclare() != null && techDeviceParam.getActualEqualDeclare() == 1) ? "等于" : "不等于");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 宣称值
                                        cell_ = row_.createCell(12);
                                        cell_.setCellValue(techDeviceParam.getDeclareValue());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 实际值
                                        cell_ = row_.createCell(13);
                                        cell_.setCellValue(techDeviceParam.getActualValue());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 认证开始时间
                                        String beginTimeStr = "";
                                        try {
                                            beginTimeStr = sdf.format(pcbaDevice.getBeginTime());
                                        } catch (Exception e) {

                                        }

                                        cell_ = row_.createCell(14);
                                        cell_.setCellValue(beginTimeStr);
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 认证结束时间
                                        String endTimeStr = "";
                                        try {
                                            endTimeStr = sdf.format(pcbaDevice.getEndTime());
                                        } catch (Exception e) {

                                        }
                                        cell_ = row_.createCell(15);
                                        cell_.setCellValue(endTimeStr);
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 认证状态
                                        cell_ = row_.createCell(16);
                                        cell_.setCellValue(pcbaDevice.getParamsStatus() != null ? (
                                                pcbaDevice.getParamsStatus() == 1 ? "认证通过" : (
                                                        pcbaDevice.getParamsStatus() == 2 ? "认证未通过" : (
                                                                pcbaDevice.getParamsStatus() == 3 ? "认证中" : (
                                                                        pcbaDevice.getParamsStatus() == 4 ? "待提交认证" : (
                                                                                pcbaDevice.getParamsStatus() == 5 ? "认证已超期" : ""
                                                                        )
                                                                )
                                                        )
                                                )
                                        ) : "待提交认证");
                                        cell_.setCellStyle(bodyContextCellStyle);
                                    }
//                                if(deviceIndex == 9 || deviceIndex == 10){
//                                    System.out.println("index=" + index);
//                                    System.out.println("beginIndex2=" + beginIndex2);
//                                }
                                    if (techDeviceParamType.getTechDeviceParamList().size() > 1) {
                                        if (index > beginIndex2) {
                                            sheet.addMergedRegion(new CellRangeAddress(beginIndex2, index, 7, 7));
                                            beginIndex2 = index + 1;
                                        } else {
                                            beginIndex2 = index + 1;
                                        }
                                    } else {
                                        beginIndex2 = index + 1;
                                    }
                                }
                            }
                        } else {
                            index++;
                            Row row_ = sheet.createRow(index);

                            // 序号
                            Cell cell_ = row_.createCell(2);
                            cell_.setCellValue(deviceIndex);
                            cell_.setCellStyle(bodyContextCellStyle);

                            // 设备名
                            cell_ = row_.createCell(3);
                            cell_.setCellValue(pcbaDevice.getPcbaDeviceNameCn());
                            cell_.setCellStyle(bodyContextCellStyle);

                            // 资产编号
                            cell_ = row_.createCell(4);
                            cell_.setCellValue(pcbaDevice.getAssetNumber());
                            cell_.setCellStyle(bodyContextCellStyle);

                            // 用途
                            cell_ = row_.createCell(5);
                            cell_.setCellValue(pcbaDevice.getPurpose());
                            cell_.setCellStyle(bodyContextCellStyle);

                            // 设备类型
                            cell_ = row_.createCell(6);
                            cell_.setCellValue(pcbaDevice.getPcbaDeviceType() != null ? pcbaDevice.getPcbaDeviceType().getPcbaDeviceTypeNameCn() : "");
                            cell_.setCellStyle(bodyContextCellStyle);

                            beginIndex2 = index + 1;
                        }
                        if (index > beginIndex1) {
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 2, 2));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 3, 3));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 4, 4));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 5, 5));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 6, 6));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 14, 14));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 15, 15));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 16, 16));
                            beginIndex1 = index + 1;
                        } else {
                            beginIndex1 = index + 1;
                        }
                    }
                }
                String fileName = excelFileName + CommonUtils.getTimestamp() + ".xlsx";
                String pathPrefix = fileSaveUrl + "exportExcels\\";
                File folder = new File(pathPrefix);
                if (!folder.isDirectory()) {
                    folder.mkdirs();
                }
                String filePath = pathPrefix + fileName;
                // 导出Excel文件
                FileOutputStream outputStream = new FileOutputStream(filePath);
                workbook.write(outputStream);
                workbook.close();
                outputStream.close();

                byte[] data = null;
                InputStream in = new FileInputStream(filePath);
                data = new byte[in.available()];
                in.read(data);
                in.close();
                java.util.Base64.Encoder encoder = java.util.Base64.getEncoder();
                String base64 = encoder.encodeToString(data);

                Map<String, Object> resMap = new HashMap<>();
                resMap.put("base64", base64);
                resMap.put("fileName", fileName);
                resMap.put("pcbaLineList", pcbaLineList);
                return ResultUtil.success(resMap);
            }else{
                // 根据 pcbaLineList结构渲染出Excel
                // 创建工作簿对象
                Workbook workbook = new XSSFWorkbook();
                String excelFileName = "线体工艺能力报告表";
                for (PcbaLine p : finalPcbaLineList) {
                    int index = 0;
                    int beginIndex1 = 1;
                    int beginIndex2 = 1;
                    // XX工厂线体设备整线能力反馈报告
                    String excelName = p.getPcbaCompany().getPcbaCompanyNameCn() + "工艺能力（" + p.getPcbaLineNameCn() + "）" + UUID.randomUUID().toString();
                    // 创建工作表对象
                    Sheet sheet = workbook.createSheet(CommonUtils.handleSheetName(excelName));

                    CellStyle bodyContextCellStyle = workbook.createCellStyle();
                    DataFormat format = workbook.createDataFormat();
                    bodyContextCellStyle.setDataFormat(format.getFormat("@"));
                    bodyContextCellStyle.setBorderBottom(BorderStyle.THIN);
                    bodyContextCellStyle.setBorderLeft(BorderStyle.THIN);
                    bodyContextCellStyle.setBorderRight(BorderStyle.THIN);
                    bodyContextCellStyle.setBorderTop(BorderStyle.THIN);
                    bodyContextCellStyle.setAlignment(HorizontalAlignment.LEFT);
                    bodyContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

                    CellStyle titleContextCellStyle = workbook.createCellStyle();
                    titleContextCellStyle.setBorderBottom(BorderStyle.THIN);
                    titleContextCellStyle.setBorderLeft(BorderStyle.THIN);
                    titleContextCellStyle.setBorderRight(BorderStyle.THIN);
                    titleContextCellStyle.setBorderTop(BorderStyle.THIN);
                    titleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
                    titleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
                    // 设置背景色为红色
                    titleContextCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
                    // 创建字体对象
                    Font titleFont = workbook.createFont();
                    // 设置字体颜色为蓝色
                    titleFont.setColor(IndexedColors.WHITE.getIndex());
                    titleFont.setBold(true);
                    titleContextCellStyle.setFont(titleFont);
                    // 设置填充类型为填充实体背景
                    titleContextCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                    Row row = sheet.createRow(0);
                    Cell cell;

                    List<Map<String, Object>> titleList = new ArrayList<>();
                    Map<String, Object> map = new HashMap<>();
                    map = new HashMap<>();
                    map.put("title", "线体名称");
                    map.put("width", 5000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "线体类型");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "工厂");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "车间");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "工序");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "外协厂实际车间名称");
                    map.put("width", 10000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "项目大类");
                    map.put("width", 5000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "项目小类");
                    map.put("width", 5000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "能力项");
                    map.put("width", 12000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "宣称值");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "实际值");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "认证开始时间");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "认证结束时间");
                    map.put("width", 8000);
                    titleList.add(map);
                    map = new HashMap<>();
                    map.put("title", "认证状态");
                    map.put("width", 8000);
                    titleList.add(map);
                    row = sheet.createRow(0);
                    for (int a = 0; a < titleList.size(); a++) {
                        sheet.setColumnWidth(a, Integer.parseInt(titleList.get(a).get("width").toString()));
                        // sheet.setDefaultRowHeight((short)450);
                        cell = row.createCell(a);
                        // 向单元格中写入数据
                        cell.setCellValue(titleList.get(a).get("title").toString());
                        cell.setCellStyle(titleContextCellStyle);
                    }
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    LineTechBigType lineTechBigType = p.getLineTechBigType();
                    if (lineTechBigType != null) {
                        if (lineTechBigType.getLineTechSmallTypeList() != null && lineTechBigType.getLineTechSmallTypeList().size() > 0) {
                            for (LineTechSmallType lineTechSmallType : lineTechBigType.getLineTechSmallTypeList()) {
                                if (lineTechSmallType.getTechCapacityRuleList() != null && lineTechSmallType.getTechCapacityRuleList().size() > 0) {
                                    for (TechCapacityRule techCapacityRule : lineTechSmallType.getTechCapacityRuleList()) {
                                        index++;
                                        Row row_ = sheet.createRow(index);

                                        // 线体名称
                                        Cell cell_ = row_.createCell(0);
                                        cell_.setCellValue(p.getPcbaLineNameCn());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 线体类型
                                        cell_ = row_.createCell(1);
                                        cell_.setCellValue(p.getLineLevel() != null ? p.getLineLevel().getLineLevelName() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 工厂
                                        cell_ = row_.createCell(2);
                                        cell_.setCellValue(p.getPcbaCompany() != null ? p.getPcbaCompany().getPcbaCompanyNameCn() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 车间
                                        cell_ = row_.createCell(3);
                                        cell_.setCellValue(p.getPcbaWorkshop() != null ? p.getPcbaWorkshop().getPcbaWorkshopNameCn() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 工序
                                        cell_ = row_.createCell(4);
                                        cell_.setCellValue(p.getPcbaProcess() != null ? p.getPcbaProcess().getPcbaProcessNameCn() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 外协厂实际车间名称
                                        cell_ = row_.createCell(5);
                                        cell_.setCellValue(p.getNotes() != null ? p.getNotes() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 项目大类
                                        cell_ = row_.createCell(6);
                                        cell_.setCellValue(lineTechBigType.getLineTechBigTypeName());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 项目小类
                                        cell_ = row_.createCell(7);
                                        cell_.setCellValue(lineTechSmallType.getLineTechSmallTypeName());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 能力项
                                        cell_ = row_.createCell(8);
                                        cell_.setCellValue(techCapacityRule.getTechCapacityRuleName());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 宣称值
                                        cell_ = row_.createCell(9);
                                        cell_.setCellValue(techCapacityRule.getDeclareValue() != null ? techCapacityRule.getDeclareValue() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 实际值
                                        cell_ = row_.createCell(10);
                                        cell_.setCellValue(techCapacityRule.getActualValue() != null ? techCapacityRule.getActualValue() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 认证开始时间
                                        String beginTimeActualStr = "";
                                        try {
                                            beginTimeActualStr = sdf.format(p.getBeginTimeActual());
                                        } catch (Exception e) {

                                        }

                                        cell_ = row_.createCell(11);
                                        cell_.setCellValue(beginTimeActualStr);
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 认证结束时间
                                        String endTimeActualStr = "";
                                        try {
                                            endTimeActualStr = sdf.format(p.getEndTimeActual());
                                        } catch (Exception e) {

                                        }
                                        cell_ = row_.createCell(12);
                                        cell_.setCellValue(endTimeActualStr);
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 认证状态
                                        cell_ = row_.createCell(13);
                                        cell_.setCellValue(p.getParamsStatusActual() != null ? (
                                                p.getParamsStatusActual() == 1 ? "认证通过" : (
                                                        p.getParamsStatusActual() == 2 ? "认证未通过" : (
                                                                p.getParamsStatusActual() == 3 ? "认证中" : (
                                                                        p.getParamsStatusActual() == 4 ? "待提交认证" : (
                                                                                p.getParamsStatusActual() == 5 ? "超出有效期" : (
                                                                                        p.getParamsStatusActual() == 6 ? "存在设备认证过期" : "待提交认证"
                                                                                )
                                                                        )
                                                                )
                                                        )
                                                )
                                        ) : "待提交认证");
                                        cell_.setCellStyle(bodyContextCellStyle);
                                    }
                                    if (lineTechSmallType.getTechCapacityRuleList().size() > 1) {
                                        if (index > beginIndex2) {
                                            sheet.addMergedRegion(new CellRangeAddress(beginIndex2, index, 7, 7));
                                            beginIndex2 = index + 1;
                                        } else {
                                            beginIndex2 = index + 1;
                                        }
                                    } else {
                                        beginIndex2 = index + 1;
                                    }
                                }
                            }
                            //if(lineBaseBigType.getLineBaseSmallTypeList().size() > 1){
                            if (index > beginIndex1) {
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 0, 0));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 1, 1));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 2, 2));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 3, 3));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 4, 4));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 5, 5));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 6, 6));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 11, 11));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 12, 12));
                                sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 13, 13));
                                beginIndex1 = index + 1;
                            } else {
                                beginIndex1 = index + 1;
                            }
                        /*}else{
                            beginIndex1 = index + 1;
                        }*/
                        }
                    } else {
                        index++;
                        Row row_ = sheet.createRow(index);

                        // 线体名称
                        Cell cell_ = row_.createCell(0);
                        cell_.setCellValue(p.getPcbaLineNameCn());
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 线体类型
                        cell_ = row_.createCell(1);
                        cell_.setCellValue(p.getLineLevel() != null ? p.getLineLevel().getLineLevelName() : "");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 工厂
                        cell_ = row_.createCell(2);
                        cell_.setCellValue(p.getPcbaCompany() != null ? p.getPcbaCompany().getPcbaCompanyNameCn() : "");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 车间
                        cell_ = row_.createCell(3);
                        cell_.setCellValue(p.getPcbaWorkshop() != null ? p.getPcbaWorkshop().getPcbaWorkshopNameCn() : "");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 工序
                        cell_ = row_.createCell(4);
                        cell_.setCellValue(p.getPcbaProcess() != null ? p.getPcbaProcess().getPcbaProcessNameCn() : "");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 外协厂实际车间名称
                        cell_ = row_.createCell(5);
                        cell_.setCellValue(p.getNotes() != null ? p.getNotes() : "");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 项目大类
                        cell_ = row_.createCell(6);
                        cell_.setCellValue("NA");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 项目小类
                        cell_ = row_.createCell(7);
                        cell_.setCellValue("NA");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 能力项
                        cell_ = row_.createCell(8);
                        cell_.setCellValue("NA");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 宣称值
                        cell_ = row_.createCell(9);
                        cell_.setCellValue("NA");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 实际值
                        cell_ = row_.createCell(10);
                        cell_.setCellValue("NA");
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 认证开始时间
                        String beginTimeActualStr = "";
                        try {
                            beginTimeActualStr = sdf.format(p.getBeginTimeActual());
                        } catch (Exception e) {

                        }

                        cell_ = row_.createCell(11);
                        cell_.setCellValue(beginTimeActualStr);
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 认证结束时间
                        String endTimeActualStr = "";
                        try {
                            endTimeActualStr = sdf.format(p.getEndTimeActual());
                        } catch (Exception e) {

                        }
                        cell_ = row_.createCell(12);
                        cell_.setCellValue(endTimeActualStr);
                        cell_.setCellStyle(bodyContextCellStyle);

                        // 认证状态
                        cell_ = row_.createCell(13);
                        cell_.setCellValue(p.getParamsStatusActual() != null ? (
                                p.getParamsStatusActual() == 1 ? "认证通过" : (
                                        p.getParamsStatusActual() == 2 ? "认证未通过" : (
                                                p.getParamsStatusActual() == 3 ? "认证中" : (
                                                        p.getParamsStatusActual() == 4 ? "待提交认证" : (
                                                                p.getParamsStatusActual() == 5 ? "超出有效期" : (
                                                                        p.getParamsStatusActual() == 6 ? "存在设备认证过期" : "待提交认证"
                                                                )
                                                        )
                                                )
                                        )
                                )
                        ) : "待提交认证");
                        cell_.setCellStyle(bodyContextCellStyle);
                    }

                    //中间空一行
                    index++;
                    index++;

                    beginIndex1 = index + 1;
                    beginIndex2 = index + 1;

                    // 渲染设备数据列表
                    List<Map<String, Object>> titleList2 = new ArrayList<>();
                    Map<String, Object> map2 = new HashMap<>();
                    map2 = new HashMap<>();
                    map2.put("title", "序号");
                    map2.put("width", 5000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "设备名");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "资产编号");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "用途");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "设备类型");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "工艺大类");
                    map2.put("width", 10000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "能力项");
                    map2.put("width", 12000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "宣称值");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "实际值");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "认证开始时间");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "认证结束时间");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    map2 = new HashMap<>();
                    map2.put("title", "认证状态");
                    map2.put("width", 8000);
                    titleList2.add(map2);
                    row = sheet.createRow(index);
                    for (int a = 0; a < titleList2.size(); a++) {
                        sheet.setColumnWidth(a, Integer.parseInt(titleList2.get(a).get("width").toString()));
                        cell = row.createCell(a + 2);
                        // 向单元格中写入数据
                        cell.setCellValue(titleList2.get(a).get("title").toString());
                        cell.setCellStyle(titleContextCellStyle);
                    }

                    int deviceIndex = 0;
                    for (PcbaDevice pcbaDevice : p.getPcbaDeviceList()) {
                        deviceIndex++;
                        if (pcbaDevice.getTechDeviceParamTypeList() != null && pcbaDevice.getTechDeviceParamTypeList().size() > 0) {
                            for (TechDeviceParamType techDeviceParamType : pcbaDevice.getTechDeviceParamTypeList()) {
                                if (techDeviceParamType.getTechDeviceParamList() != null && techDeviceParamType.getTechDeviceParamList().size() > 0) {
                                    for (TechDeviceParam techDeviceParam : techDeviceParamType.getTechDeviceParamList()) {
                                        index++;
                                        Row row_ = sheet.createRow(index);

                                        // 序号
                                        Cell cell_ = row_.createCell(2);
                                        cell_.setCellValue(deviceIndex);
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 设备名
                                        cell_ = row_.createCell(3);
                                        cell_.setCellValue(pcbaDevice.getPcbaDeviceNameCn());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 资产编号
                                        cell_ = row_.createCell(4);
                                        cell_.setCellValue(pcbaDevice.getAssetNumber());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 用途
                                        cell_ = row_.createCell(5);
                                        cell_.setCellValue(pcbaDevice.getPurpose());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 设备类型
                                        cell_ = row_.createCell(6);
                                        cell_.setCellValue(pcbaDevice.getPcbaDeviceType() != null ? pcbaDevice.getPcbaDeviceType().getPcbaDeviceTypeNameCn() : "");
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 工艺大类
                                        cell_ = row_.createCell(7);
                                        cell_.setCellValue(techDeviceParamType.getTechDeviceParamTypeName());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 能力项
                                        cell_ = row_.createCell(8);
                                        cell_.setCellValue(techDeviceParam.getTechDeviceParamNameCn());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 宣称值
                                        cell_ = row_.createCell(9);
                                        cell_.setCellValue(techDeviceParam.getDeclareValue());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 实际值
                                        cell_ = row_.createCell(10);
                                        cell_.setCellValue(techDeviceParam.getActualValue());
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 认证开始时间
                                        String beginTimeStr = "";
                                        try {
                                            beginTimeStr = sdf.format(pcbaDevice.getBeginTime());
                                        } catch (Exception e) {

                                        }

                                        cell_ = row_.createCell(11);
                                        cell_.setCellValue(beginTimeStr);
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 认证结束时间
                                        String endTimeStr = "";
                                        try {
                                            endTimeStr = sdf.format(pcbaDevice.getEndTime());
                                        } catch (Exception e) {

                                        }
                                        cell_ = row_.createCell(12);
                                        cell_.setCellValue(endTimeStr);
                                        cell_.setCellStyle(bodyContextCellStyle);

                                        // 认证状态
                                        cell_ = row_.createCell(13);
                                        cell_.setCellValue(pcbaDevice.getParamsStatus() != null ? (
                                                pcbaDevice.getParamsStatus() == 1 ? "认证通过" : (
                                                        pcbaDevice.getParamsStatus() == 2 ? "认证未通过" : (
                                                                pcbaDevice.getParamsStatus() == 3 ? "认证中" : (
                                                                        pcbaDevice.getParamsStatus() == 4 ? "待提交认证" : (
                                                                                pcbaDevice.getParamsStatus() == 5 ? "认证已超期" : ""
                                                                        )
                                                                )
                                                        )
                                                )
                                        ) : "待提交认证");
                                        cell_.setCellStyle(bodyContextCellStyle);
                                    }
//                                if(deviceIndex == 9 || deviceIndex == 10){
//                                    System.out.println("index=" + index);
//                                    System.out.println("beginIndex2=" + beginIndex2);
//                                }
                                    if (techDeviceParamType.getTechDeviceParamList().size() > 1) {
                                        if (index > beginIndex2) {
                                            sheet.addMergedRegion(new CellRangeAddress(beginIndex2, index, 7, 7));
                                            beginIndex2 = index + 1;
                                        } else {
                                            beginIndex2 = index + 1;
                                        }
                                    } else {
                                        beginIndex2 = index + 1;
                                    }
                                }
                            }
                        } else {
                            index++;
                            Row row_ = sheet.createRow(index);

                            // 序号
                            Cell cell_ = row_.createCell(2);
                            cell_.setCellValue(deviceIndex);
                            cell_.setCellStyle(bodyContextCellStyle);

                            // 设备名
                            cell_ = row_.createCell(3);
                            cell_.setCellValue(pcbaDevice.getPcbaDeviceNameCn());
                            cell_.setCellStyle(bodyContextCellStyle);

                            // 资产编号
                            cell_ = row_.createCell(4);
                            cell_.setCellValue(pcbaDevice.getAssetNumber());
                            cell_.setCellStyle(bodyContextCellStyle);

                            // 用途
                            cell_ = row_.createCell(5);
                            cell_.setCellValue(pcbaDevice.getPurpose());
                            cell_.setCellStyle(bodyContextCellStyle);

                            // 设备类型
                            cell_ = row_.createCell(6);
                            cell_.setCellValue(pcbaDevice.getPcbaDeviceType() != null ? pcbaDevice.getPcbaDeviceType().getPcbaDeviceTypeNameCn() : "");
                            cell_.setCellStyle(bodyContextCellStyle);

                            beginIndex2 = index + 1;
                        }
                        if (index > beginIndex1) {
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 2, 2));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 3, 3));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 4, 4));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 5, 5));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 6, 6));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 11, 11));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 12, 12));
                            sheet.addMergedRegion(new CellRangeAddress(beginIndex1, index, 13, 13));
                            beginIndex1 = index + 1;
                        } else {
                            beginIndex1 = index + 1;
                        }
                    }
                }
                String fileName = excelFileName + CommonUtils.getTimestamp() + ".xlsx";
                String pathPrefix = fileSaveUrl + "exportExcels\\";
                File folder = new File(pathPrefix);
                if (!folder.isDirectory()) {
                    folder.mkdirs();
                }
                String filePath = pathPrefix + fileName;
                // 导出Excel文件
                FileOutputStream outputStream = new FileOutputStream(filePath);
                workbook.write(outputStream);
                workbook.close();
                outputStream.close();

                byte[] data = null;
                InputStream in = new FileInputStream(filePath);
                data = new byte[in.available()];
                in.read(data);
                in.close();
                java.util.Base64.Encoder encoder = java.util.Base64.getEncoder();
                String base64 = encoder.encodeToString(data);

                Map<String, Object> resMap = new HashMap<>();
                resMap.put("base64", base64);
                resMap.put("fileName", fileName);
                resMap.put("pcbaLineList", pcbaLineList);
                return ResultUtil.success(resMap);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result importPcbaLineAndDeviceParamsExcel(MultipartFile file) {
        return null;
    }

    /**
     * 1.如果是smt线体，则判断其下的设备 实际工艺能力是否都是认证通过状态，当且仅当全部认证通过才允许审核
     * 2.如果是非smt线体，则根据其下设备的实际工艺能力，当且仅当全部认证通过，则自动修改状态为认证通过
     */
    @Override
    public Result updateLineStatusByDevicesStatus(Integer pcbaLineId) {
        try {
            if (pcbaLineId == null || "".equals(pcbaLineId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaLineId", "Miss Param pcbaLineId", null);
            }
            PcbaLine pcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineId);
            Integer pcbaLineType = pcbaLine.getPcbaLineType();
            List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLineId);
            boolean isPcbaDeviceListValid = true;
            for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                Integer paramsStatus = pcbaDevice.getParamsStatus();
                if (paramsStatus == null || paramsStatus != 1) {
                    isPcbaDeviceListValid = false;
                    break;
                }
            }
            if (pcbaLineType == 1) {
                if (isPcbaDeviceListValid) {
                    return ResultUtil.success(null);
                }
                return ResultUtil.error(500, "线体下存在设备的实际能力没有认证通过，无法审核", "Can Not Audit", null);
            } else {
                if (isPcbaDeviceListValid) {
                    // 直接修改线体的审核状态
                    pcbaLineDao.auditPcbaLineTechActual("", pcbaLineId, 1, new Date());

                    // 级联触发 线体的最终状态
                    coreAlgorithmService.cascadeUpdateLineFinalStatus(3, null, null, pcbaLineId);

                    return ResultUtil.success(null);
                }
                return ResultUtil.error(500, "线体下存在设备的实际能力没有认证通过，无法审核", "Can Not Audit", null);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getAllNeedToAgeCloseLine(String data) {
        try {
            JSONObject jsonObject = JSONObject.parseObject(data);
            String pcbaLineNames = jsonObject.getString("pcbaLineNames");
            String chooseCompanyAndWorkshop = jsonObject.getString("chooseCompanyAndWorkshop");
            String pcbaProcessIds = jsonObject.getString("pcbaProcessIds");
            String status = jsonObject.getString("status");

            List<String> pbcaLineNameList = new ArrayList<>();
            List<String> pcbaWorkshopIdList = new ArrayList<>();
            List<String> pcbaProcessIdList = new ArrayList<>();
            if (pcbaLineNames != null && !"".equals(pcbaLineNames)) {
                String[] split = pcbaLineNames.split(",");
                pbcaLineNameList.addAll(Arrays.asList(split));
            }
            if (chooseCompanyAndWorkshop != null && !"".equals(chooseCompanyAndWorkshop)) {
                JSONArray jsonArray = JSONArray.parseArray(chooseCompanyAndWorkshop);
                for (int a = 0; a < jsonArray.size(); a++) {
                    JSONArray jsonArray1 = jsonArray.getJSONArray(a);
                    if (jsonArray1.size() == 2) {
                        pcbaWorkshopIdList.add(jsonArray1.get(1).toString());
                    }
                }

            }
            if (pcbaProcessIds != null && !"".equals(pcbaProcessIds)) {
                String[] split = pcbaProcessIds.split(",");
                pcbaProcessIdList.addAll(Arrays.asList(split));
            }

            List<Integer> companyIdList = strToCompanys.getPcbaCompanyIdListFromStr();

            List<PcbaLine> list = pcbaLineDao.getAllPcbaLineView(pbcaLineNameList, pcbaWorkshopIdList, pcbaProcessIdList, Integer.parseInt(status), 1, null, null, companyIdList);

            for (PcbaLine pcbaLine : list) {
                pcbaLine.setLineLevel(lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevel()));
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                pcbaLine.setPcbaDeviceNums(pcbaDeviceList.size());
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    List<String> loopCloseFilesList = new ArrayList<>();
                    List<String> ageCloseFilesList = new ArrayList<>();
                    if(pcbaDevice.getLoopCloseFiles() != null && !"".equals(pcbaDevice.getLoopCloseFiles())){
                        String[] split = pcbaDevice.getLoopCloseFiles().split(",");
                        loopCloseFilesList.addAll(Arrays.asList(split));
                    }
                    pcbaDevice.setLoopCloseFilesList(loopCloseFilesList);
                    if(pcbaDevice.getAgeCloseFiles() != null && !"".equals(pcbaDevice.getAgeCloseFiles())){
                        String[] split = pcbaDevice.getAgeCloseFiles().split(",");
                        ageCloseFilesList.addAll(Arrays.asList(split));
                    }
                    pcbaDevice.setAgeCloseFilesList(ageCloseFilesList);
                    if (pcbaDevice.getProductTime() != null && !"".equals(pcbaDevice.getProductTime().toString())) {
                        Date d1 = new Date();
                        LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        LocalDate ld2 = pcbaDevice.getProductTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        double age = CommonUtils.calculateYearDifference(ld2, ld1);
                        pcbaDevice.setAge(age);
                        Result result = coreAlgorithmService.calcIsAgeOverdueInLine(pcbaDevice);
                        if (result.getCode() == 200) {
                            int i = Integer.parseInt(result.getData().toString());
                            pcbaDevice.setIsHasAgeOverdueInLine(i);
                        }
                    }
                    PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                    if (pcbaDeviceResource != null) {
                        pcbaDeviceResource.setBrand(brandDao.getBrandById(pcbaDeviceResource.getBrandId()));
                        pcbaDeviceResource.setBrandType(brandTypeDao.getBrandTypeById(pcbaDeviceResource.getBrandTypeId()));
                        pcbaDevice.setPcbaDeviceResource(pcbaDeviceResource);
                        pcbaDevice.setPcbaDeviceType(pcbaDeviceTypeDao.getById(pcbaDevice.getPcbaDeviceTypeId()));
                    }
                }
                int isHasAgeOverdueInLine = 2;
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    if (pcbaDevice.getIsHasAgeOverdueInLine() != null && pcbaDevice.getIsHasAgeOverdueInLine() == 1) {
                        isHasAgeOverdueInLine = 1;
                        break;
                    }
                }
                pcbaLine.setPcbaDeviceList(pcbaDeviceList);
                pcbaLine.setIsHasAgeOverdueInLine(isHasAgeOverdueInLine);
                PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId());
                PcbaWorkshop pcbaWorkshop = pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId());
                PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId());
                pcbaLine.setPcbaCompany(pcbaCompany);
                pcbaLine.setPcbaWorkshop(pcbaWorkshop);
                pcbaLine.setPcbaProcess(pcbaProcess);
            }
            List<PcbaLine> finalList = new ArrayList<>();
            for (PcbaLine pcbaLine : list) {
                if (pcbaLine.getIsHasAgeOverdueInLine() == 1) {
                    finalList.add(pcbaLine);
                }
            }
            return ResultUtil.success(finalList);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getAllNeedToLoopCloseLineWaitAudit(String data) {
        try {

            JSONObject jsonObject = JSONObject.parseObject(data);
            String pcbaLineNames = jsonObject.getString("pcbaLineNames");
            String chooseCompanyAndWorkshop = jsonObject.getString("chooseCompanyAndWorkshop");
            String pcbaProcessIds = jsonObject.getString("pcbaProcessIds");
            String status = jsonObject.getString("status");

            List<String> pbcaLineNameList = new ArrayList<>();
            List<String> pcbaWorkshopIdList = new ArrayList<>();
            List<String> pcbaProcessIdList = new ArrayList<>();
            if (pcbaLineNames != null && !"".equals(pcbaLineNames)) {
                String[] split = pcbaLineNames.split(",");
                pbcaLineNameList.addAll(Arrays.asList(split));
            }
            if (chooseCompanyAndWorkshop != null && !"".equals(chooseCompanyAndWorkshop)) {
                JSONArray jsonArray = JSONArray.parseArray(chooseCompanyAndWorkshop);
                for (int a = 0; a < jsonArray.size(); a++) {
                    JSONArray jsonArray1 = jsonArray.getJSONArray(a);
                    if (jsonArray1.size() == 2) {
                        pcbaWorkshopIdList.add(jsonArray1.get(1).toString());
                    }
                }

            }
            if (pcbaProcessIds != null && !"".equals(pcbaProcessIds)) {
                String[] split = pcbaProcessIds.split(",");
                pcbaProcessIdList.addAll(Arrays.asList(split));
            }

            List<Integer> companyIdList = strToCompanys.getPcbaCompanyIdListFromStr();

            // 高端线体的列表
            List<PcbaLine> highLineList = new ArrayList<>();

            List<PcbaLine> list = pcbaLineDao.getAllPcbaLineView(pbcaLineNameList, pcbaWorkshopIdList, pcbaProcessIdList, Integer.parseInt(status), 1, null, null, companyIdList);
            for (PcbaLine pcbaLine : list) {
                LineLevel lineLevel = lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevel());
                if (lineLevel != null && lineLevel.getLineLevelName().contains("高端")) {
                    highLineList.add(pcbaLine);
                }
            }
            for (PcbaLine pcbaLine : highLineList) {
                pcbaLine.setLineLevel(lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevel()));
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                pcbaLine.setPcbaDeviceNums(pcbaDeviceList.size());
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    List<String> loopCloseFilesList = new ArrayList<>();
                    List<String> ageCloseFilesList = new ArrayList<>();
                    if(pcbaDevice.getLoopCloseFiles() != null && !"".equals(pcbaDevice.getLoopCloseFiles())){
                        String[] split = pcbaDevice.getLoopCloseFiles().split(",");
                        loopCloseFilesList.addAll(Arrays.asList(split));
                    }
                    pcbaDevice.setLoopCloseFilesList(loopCloseFilesList);
                    if(pcbaDevice.getAgeCloseFiles() != null && !"".equals(pcbaDevice.getAgeCloseFiles())){
                        String[] split = pcbaDevice.getAgeCloseFiles().split(",");
                        ageCloseFilesList.addAll(Arrays.asList(split));
                    }
                    pcbaDevice.setAgeCloseFilesList(ageCloseFilesList);
                    if (pcbaDevice.getProductTime() != null && !"".equals(pcbaDevice.getProductTime().toString())) {
                        Date d1 = new Date();
                        LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        LocalDate ld2 = pcbaDevice.getProductTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        double age = CommonUtils.calculateYearDifference(ld2, ld1);
                        pcbaDevice.setAge(age);

                        Result result = coreAlgorithmService.calcIsOverSixYearInHighLine(pcbaDevice, pcbaLine.getPcbaLineLevel());
                        if (result.getCode() == 200) {
                            int i = Integer.parseInt(result.getData().toString());
                            pcbaDevice.setIsOverSixYearInHighLine(i);
                        }
                    }
                    PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                    if (pcbaDeviceResource != null) {
                        pcbaDeviceResource.setBrand(brandDao.getBrandById(pcbaDeviceResource.getBrandId()));
                        pcbaDeviceResource.setBrandType(brandTypeDao.getBrandTypeById(pcbaDeviceResource.getBrandTypeId()));
                        pcbaDevice.setPcbaDeviceResource(pcbaDeviceResource);
                        pcbaDevice.setPcbaDeviceType(pcbaDeviceTypeDao.getById(pcbaDevice.getPcbaDeviceTypeId()));
                    }
                }
                int isOverSixYearInHighLine = 2;
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    if (pcbaDevice.getIsOverSixYearInHighLine() != null && pcbaDevice.getIsOverSixYearInHighLine() == 1) {
                        isOverSixYearInHighLine = 1;
                        break;
                    }
                }
                pcbaLine.setPcbaDeviceList(pcbaDeviceList);
                pcbaLine.setIsOverSixYearInHighLine(isOverSixYearInHighLine);
                PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId());
                PcbaWorkshop pcbaWorkshop = pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId());
                PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId());
                pcbaLine.setPcbaCompany(pcbaCompany);
                pcbaLine.setPcbaWorkshop(pcbaWorkshop);
                pcbaLine.setPcbaProcess(pcbaProcess);
            }
            List<PcbaLine> finalList = new ArrayList<>();
            for (PcbaLine pcbaLine : highLineList) {
                if (pcbaLine.getIsOverSixYearInHighLine() == 1) {
                    finalList.add(pcbaLine);
                }
            }
            List<PcbaLine> finalList__ = new ArrayList<>();
            for (PcbaLine pcbaLine : finalList) {
                for (PcbaDevice pcbaDevice : pcbaLine.getPcbaDeviceList()) {
                    if(pcbaDevice.getLoopCloseStatus() != null && pcbaDevice.getLoopCloseStatus() == 3){
                        finalList__.add(pcbaLine);
                        break;
                    }
                }
            }
            return ResultUtil.success(finalList__);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getAllNeedToAgeCloseLineWaitAudit(String data) {
        try {
            JSONObject jsonObject = JSONObject.parseObject(data);
            String pcbaLineNames = jsonObject.getString("pcbaLineNames");
            String chooseCompanyAndWorkshop = jsonObject.getString("chooseCompanyAndWorkshop");
            String pcbaProcessIds = jsonObject.getString("pcbaProcessIds");
            String status = jsonObject.getString("status");

            List<String> pbcaLineNameList = new ArrayList<>();
            List<String> pcbaWorkshopIdList = new ArrayList<>();
            List<String> pcbaProcessIdList = new ArrayList<>();
            if (pcbaLineNames != null && !"".equals(pcbaLineNames)) {
                String[] split = pcbaLineNames.split(",");
                pbcaLineNameList.addAll(Arrays.asList(split));
            }
            if (chooseCompanyAndWorkshop != null && !"".equals(chooseCompanyAndWorkshop)) {
                JSONArray jsonArray = JSONArray.parseArray(chooseCompanyAndWorkshop);
                for (int a = 0; a < jsonArray.size(); a++) {
                    JSONArray jsonArray1 = jsonArray.getJSONArray(a);
                    if (jsonArray1.size() == 2) {
                        pcbaWorkshopIdList.add(jsonArray1.get(1).toString());
                    }
                }

            }
            if (pcbaProcessIds != null && !"".equals(pcbaProcessIds)) {
                String[] split = pcbaProcessIds.split(",");
                pcbaProcessIdList.addAll(Arrays.asList(split));
            }

            List<Integer> companyIdList = strToCompanys.getPcbaCompanyIdListFromStr();

            List<PcbaLine> list = pcbaLineDao.getAllPcbaLineView(pbcaLineNameList, pcbaWorkshopIdList, pcbaProcessIdList, Integer.parseInt(status), 1, null, null, companyIdList);

            for (PcbaLine pcbaLine : list) {
                pcbaLine.setLineLevel(lineLevelDao.getLineLevelById(pcbaLine.getPcbaLineLevel()));
                List<PcbaDevice> pcbaDeviceList = pcbaDeviceDao.getPcbaDeviceByLine(pcbaLine.getPcbaLineId());
                pcbaLine.setPcbaDeviceNums(pcbaDeviceList.size());
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    List<String> loopCloseFilesList = new ArrayList<>();
                    List<String> ageCloseFilesList = new ArrayList<>();
                    if(pcbaDevice.getLoopCloseFiles() != null && !"".equals(pcbaDevice.getLoopCloseFiles())){
                        String[] split = pcbaDevice.getLoopCloseFiles().split(",");
                        loopCloseFilesList.addAll(Arrays.asList(split));
                    }
                    pcbaDevice.setLoopCloseFilesList(loopCloseFilesList);
                    if(pcbaDevice.getAgeCloseFiles() != null && !"".equals(pcbaDevice.getAgeCloseFiles())){
                        String[] split = pcbaDevice.getAgeCloseFiles().split(",");
                        ageCloseFilesList.addAll(Arrays.asList(split));
                    }
                    pcbaDevice.setAgeCloseFilesList(ageCloseFilesList);
                    if (pcbaDevice.getProductTime() != null && !"".equals(pcbaDevice.getProductTime().toString())) {
                        Date d1 = new Date();
                        LocalDate ld1 = d1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        LocalDate ld2 = pcbaDevice.getProductTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        double age = CommonUtils.calculateYearDifference(ld2, ld1);
                        pcbaDevice.setAge(age);
                        Result result = coreAlgorithmService.calcIsAgeOverdueInLine(pcbaDevice);
                        if (result.getCode() == 200) {
                            int i = Integer.parseInt(result.getData().toString());
                            pcbaDevice.setIsHasAgeOverdueInLine(i);
                        }
                    }
                    PcbaDeviceResource pcbaDeviceResource = pcbaDeviceResourceDao.getById(pcbaDevice.getPcbaDeviceResourceId());
                    if (pcbaDeviceResource != null) {
                        pcbaDeviceResource.setBrand(brandDao.getBrandById(pcbaDeviceResource.getBrandId()));
                        pcbaDeviceResource.setBrandType(brandTypeDao.getBrandTypeById(pcbaDeviceResource.getBrandTypeId()));
                        pcbaDevice.setPcbaDeviceResource(pcbaDeviceResource);
                        pcbaDevice.setPcbaDeviceType(pcbaDeviceTypeDao.getById(pcbaDevice.getPcbaDeviceTypeId()));
                    }
                }
                int isHasAgeOverdueInLine = 2;
                for (PcbaDevice pcbaDevice : pcbaDeviceList) {
                    if (pcbaDevice.getIsHasAgeOverdueInLine() != null && pcbaDevice.getIsHasAgeOverdueInLine() == 1) {
                        isHasAgeOverdueInLine = 1;
                        break;
                    }
                }
                pcbaLine.setPcbaDeviceList(pcbaDeviceList);
                pcbaLine.setIsHasAgeOverdueInLine(isHasAgeOverdueInLine);
                PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId());
                PcbaWorkshop pcbaWorkshop = pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId());
                PcbaProcess pcbaProcess = pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId());
                pcbaLine.setPcbaCompany(pcbaCompany);
                pcbaLine.setPcbaWorkshop(pcbaWorkshop);
                pcbaLine.setPcbaProcess(pcbaProcess);
            }
            List<PcbaLine> finalList = new ArrayList<>();
            for (PcbaLine pcbaLine : list) {
                if (pcbaLine.getIsHasAgeOverdueInLine() == 1) {
                    finalList.add(pcbaLine);
                }
            }
            List<PcbaLine> finalList__ = new ArrayList<>();
            for (PcbaLine pcbaLine : finalList) {
                for (PcbaDevice pcbaDevice : pcbaLine.getPcbaDeviceList()) {
                    if(pcbaDevice.getAgeCloseStatus() != null && pcbaDevice.getAgeCloseStatus() == 3){
                        finalList__.add(pcbaLine);
                        break;
                    }
                }
            }
            return ResultUtil.success(finalList__);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }
}
